From owner-svn-soc-all@FreeBSD.ORG Thu Sep 26 13:01:44 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 03135D0 for ; Thu, 26 Sep 2013 13:01:44 +0000 (UTC) (envelope-from ambarisha@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D59EC288B for ; Thu, 26 Sep 2013 13:01:43 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8QD1hrH041669 for ; Thu, 26 Sep 2013 13:01:43 GMT (envelope-from ambarisha@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r8QD1hB2041653 for svn-soc-all@FreeBSD.org; Thu, 26 Sep 2013 13:01:43 GMT (envelope-from ambarisha@FreeBSD.org) Date: Thu, 26 Sep 2013 13:01:43 GMT Message-Id: <201309261301.r8QD1hB2041653@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ambarisha@FreeBSD.org using -f From: ambarisha@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257722 - soc2013/ambarisha/head/usr.bin/dmget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Sep 2013 13:01:44 -0000 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 -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 + +#include +#include + +#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);