From: Fredrik Tolf Date: Tue, 27 May 2008 12:45:02 +0000 (+0200) Subject: Added XATTR logging facility to the reqstat module. X-Git-Tag: 1.3~11^2^2~10^2~1 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=5dce4f6c7d1f5fb0a4d4bcf72c11ee0c91ebcfdf;p=doldaconnect.git Added XATTR logging facility to the reqstat module. --- diff --git a/daemon/reqstat.c b/daemon/reqstat.c index cbe1c72..34b7ce3 100644 --- a/daemon/reqstat.c +++ b/daemon/reqstat.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -61,19 +62,52 @@ void filelog(char *format, ...) fclose(out); } +void xainc(wchar_t *file, char *an, off_t inc) +{ + char buf[32]; + ssize_t al; + off_t val; + char *fn; + + if((fn = icswcstombs(file, NULL, NULL)) == NULL) { + flog(LOG_WARNING, "could not convert filename %ls into local charset: %s", file, strerror(errno)); + return; + } + if((al = getxattr(fn, an, buf, sizeof(buf) - 1)) < 0) { + if(errno != ENOATTR) { + flog(LOG_WARNING, "could not get xattr %s on %s: %s", an, fn, strerror(errno)); + return; + } + val = 0; + } else { + buf[al] = 0; + val = strtoll(buf, NULL, 10); + } + val += inc; + al = snprintf(buf, sizeof(buf), "%ji", (intmax_t)val); + if(setxattr(fn, an, buf, al, 0) < 0) + flog(LOG_WARNING, "could not set xattr %s on %s: %s", an, fn, strerror(errno)); +} + void request(struct transfer *transfer, struct trdata *data) { filelog("request %ls", transfer->path); + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-req", 1); } void start(struct transfer *transfer, struct trdata *data) { filelog("start %ls at %zi", transfer->path, data->startpos); + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-started", 1); } void finish(struct transfer *transfer, struct trdata *data) { filelog("finish %ls at %zi, total %zi", transfer->path, transfer->curpos, transfer->curpos - data->startpos); + if(confgetint("reqstat", "xa")) + xainc(transfer->path, "user.dc-bytes", transfer->curpos - data->startpos); } static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *data) @@ -140,6 +174,12 @@ static struct configvar myvars[] = { /** The name of a file to log upload request information to. If * unspecified, upload requests will not be logged. */ {CONF_VAR_STRING, "file", {.str = L""}}, + /** If set to true, upload statistics of files will be accumulated + * in counters stored in extends attributes (see attr(5)) on the + * files themselves. The data accumulated is the number of + * requests, the number of successfully started uploads and the + * number of uploaded bytes. */ + {CONF_VAR_BOOL, "xa", {.num = 0}}, {CONF_VAR_END} };