Date: Thu, 26 Sep 2013 13:01:43 GMT From: ambarisha@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257722 - soc2013/ambarisha/head/usr.bin/dmget Message-ID: <201309261301.r8QD1hB2041653@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ambarisha Date: Thu Sep 26 13:01:43 2013 New Revision: 257722 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257722 Log: Added dms status dump functionality to dmget with -X command line switch Added: soc2013/ambarisha/head/usr.bin/dmget/dmsumm.c soc2013/ambarisha/head/usr.bin/dmget/dmsumm.h Modified: soc2013/ambarisha/head/usr.bin/dmget/Makefile soc2013/ambarisha/head/usr.bin/dmget/dm.h soc2013/ambarisha/head/usr.bin/dmget/fetch.c Modified: soc2013/ambarisha/head/usr.bin/dmget/Makefile ============================================================================== --- soc2013/ambarisha/head/usr.bin/dmget/Makefile Thu Sep 26 12:37:47 2013 (r257721) +++ soc2013/ambarisha/head/usr.bin/dmget/Makefile Thu Sep 26 13:01:43 2013 (r257722) @@ -2,7 +2,7 @@ .include <bsd.own.mk> -SRCS= fetch.c utils.c dmget.c +SRCS= fetch.c utils.c dmget.c dmsumm.c PROG= dmget CSTD?= c99 .if ${MK_OPENSSL} != "no" Modified: soc2013/ambarisha/head/usr.bin/dmget/dm.h ============================================================================== --- soc2013/ambarisha/head/usr.bin/dmget/dm.h Thu Sep 26 12:37:47 2013 (r257721) +++ soc2013/ambarisha/head/usr.bin/dmget/dm.h Thu Sep 26 13:01:43 2013 (r257722) @@ -68,6 +68,21 @@ char *buf; }; +struct dmsumm { + char name[64]; + char mirror[64]; + + enum { + RUNNING = 0, + DONE, + DUPLICATE + } state; + + off_t size; + off_t rcvd; + long eta; +}; + struct xferstat { char name[64]; struct timeval start; /* start of transfer */ @@ -85,5 +100,7 @@ #define DMAUTHRESP 4 #define DMSIG 5 #define DMSTAT 6 +#define DMDUMPREQ 7 +#define DMDUMPRESP 8 #endif /* _DMCLIENT_H */ Added: soc2013/ambarisha/head/usr.bin/dmget/dmsumm.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/ambarisha/head/usr.bin/dmget/dmsumm.c Thu Sep 26 13:01:43 2013 (r257722) @@ -0,0 +1,86 @@ + +#include <stdio.h> + +#include <sys/un.h> +#include <sys/socket.h> + +#include "dmsumm.h" +#include "dm.h" +#include "utils.h" + +int +receive_summary(int sock, struct dmsumm **summs, int *nsumms) +{ + struct dmmsg *dmmsg; + + dmmsg = recv_dmmsg(sock); + if (dmmsg == NULL) + return -1; + + *nsumms = dmmsg->len / sizeof(struct dmsumm); + *summs = (struct dmsumm *)dmmsg->buf; + + return 0; +} + +int +output_summary(FILE *outf, struct dmsumm *summs, int nsumms) +{ + int i; + double percent; + + for (i = 0; i < nsumms; i++) { + percent = 100 * summs[i].rcvd / summs[i].size ; + fprintf(outf, "%64s\t""%f%%\t""%d\t""%64s\t", + summs[i].name, percent, summs[i].eta, + summs[i].mirror); + } +} + +int +dump_status_summary(FILE *outf) +{ + int sock, ret, nsumms; + struct sockaddr_un dms_addr; + struct dmmsg dmmsg; + struct dmsumm *summs; + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) { + fprintf(stderr, "dmget: Could not create socket" + " (%s)\n", strerror(errno)); + return -1; + } + + dms_addr.sun_family = AF_UNIX; + strncpy(dms_addr.sun_path, DMS_UDS_PATH, sizeof(dms_addr.sun_path)); + ret = connect(sock, (struct sockaddr *) &dms_addr, sizeof(dms_addr)); + if (ret == -1) { + fprintf(stderr, "dmget: Could not connect to daemon" + " (%s)\n", strerror(errno)); + return -1; + } + + //if (sigint) + // goto signal; + + dmmsg.op = DMDUMPREQ; + dmmsg.len = 0; + dmmsg.buf = NULL; + ret = send_dmmsg(sock, dmmsg); + if (ret == -1) { + close(sock); + return -1; + } + + ret = receive_summary(sock, &summs, &nsumms); + if (ret == -1) { + close(sock); + return -1; + } + + output_summary(outf, summs, nsumms); + + free(summs); + return nsumms; +} Added: soc2013/ambarisha/head/usr.bin/dmget/dmsumm.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/ambarisha/head/usr.bin/dmget/dmsumm.h Thu Sep 26 13:01:43 2013 (r257722) @@ -0,0 +1,6 @@ +#ifndef _DM_STATUS_H_ +#define _DM_STATUS_H_ + +int dump_status_summary(FILE *); + +#endif Modified: soc2013/ambarisha/head/usr.bin/dmget/fetch.c ============================================================================== --- soc2013/ambarisha/head/usr.bin/dmget/fetch.c Thu Sep 26 12:37:47 2013 (r257721) +++ soc2013/ambarisha/head/usr.bin/dmget/fetch.c Thu Sep 26 13:01:43 2013 (r257722) @@ -49,6 +49,7 @@ #include "dmget.h" #include "dm.h" +#include "dmsumm.h" #define MINBUFSIZE 4096 #define TIMEOUT 120 @@ -354,7 +355,7 @@ int c, e, r; while ((c = getopt(argc, argv, - "146AaB:bc:C:dFf:Hh:i:lMmN:nPpo:qRrS:sT:tUvw:")) != -1) + "146AaB:bc:C:dFf:Hh:i:lMmN:nPpo:qRrS:sT:tUvw:X")) != -1) switch (c) { case '1': once_flag = 1; @@ -471,6 +472,9 @@ if (*optarg == '\0' || *end != '\0') errx(1, "invalid delay (%s)", optarg); break; + case 'X': + dump_status_summary(fdopen(STDOUT_FILENO, "w")); + exit(0); default: usage(); exit(1);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309261301.r8QD1hB2041653>