diff --git a/bootstrap.conf b/bootstrap.conf index 66a88cda7b..c112ccd8a8 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -89,6 +89,7 @@ sigaction sigpipe snprintf socket +stat-time stdarg stpcpy strchrnul diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index d0e4319c50..9f93db810a 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -141,6 +141,11 @@ <mode>0744</mode> <label>virt_image_t</label> </permissions> + <timestamps> + <atime>1341933637.273190990</atime> + <mtime>1341930622.047245868</mtime> + <ctime>1341930622.047245868</ctime> + </timestamps> <encryption type='...'> ... </encryption> @@ -172,6 +177,19 @@ contains the MAC (eg SELinux) label string. Since 0.4.1 +
timestamps
+
Provides timing information about the volume. Up to four + sub-elements are present, + where atime, btime, ctime + and mtime hold the access, birth, change and + modification time of the volume, where known. The used time + format is <seconds>.<nanoseconds> since the + beginning of the epoch (1 Jan 1970). If nanosecond resolution + is 0 or otherwise unsupported by the host OS or filesystem, + then the nanoseconds part is omitted. This is a readonly + attribute and is ignored when creating a volume. + Since 0.10.0 +
encryption
If present, specifies how the volume is encrypted. See the Storage Encryption page diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng index 0b9933d56c..8335b616fd 100644 --- a/docs/schemas/storagevol.rng +++ b/docs/schemas/storagevol.rng @@ -63,6 +63,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [0-9]+(\.[0-9]{0,9})? + + + @@ -72,6 +107,7 @@ + diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 18170474d7..9dee000f6b 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -55,6 +55,8 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ dontwarn="$dontwarn -Wunsafe-loop-optimizations" # Things like virAsprintf mean we can't use this dontwarn="$dontwarn -Wformat-nonliteral" + # Gnulib's stat-time.h violates this + dontwarn="$dontwarn -Waggregate-return" # We might fundamentally need some of these disabled forever, but # ideally we'd turn many of them on diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index b07a7aa0b3..3132aae3ba 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -286,9 +286,11 @@ virStorageVolDefFree(virStorageVolDefPtr def) { VIR_FREE(def->target.path); VIR_FREE(def->target.perms.label); + VIR_FREE(def->target.timestamps); virStorageEncryptionFree(def->target.encryption); VIR_FREE(def->backingStore.path); VIR_FREE(def->backingStore.perms.label); + VIR_FREE(def->backingStore.timestamps); virStorageEncryptionFree(def->backingStore.encryption); VIR_FREE(def); } @@ -1252,6 +1254,19 @@ virStorageVolDefParseFile(virStoragePoolDefPtr pool, return virStorageVolDefParse(pool, NULL, filename); } +static void +virStorageVolTimestampFormat(virBufferPtr buf, const char *name, + struct timespec *ts) +{ + if (ts->tv_nsec < 0) + return; + virBufferAsprintf(buf, " <%s>%llu", name, + (unsigned long long) ts->tv_sec); + if (ts->tv_nsec) + virBufferAsprintf(buf, ".%09ld", ts->tv_nsec); + virBufferAsprintf(buf, "\n", name); +} + static int virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virBufferPtr buf, @@ -1288,6 +1303,15 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virBufferAddLit(buf," \n"); + if (def->timestamps) { + virBufferAddLit(buf, " \n"); + virStorageVolTimestampFormat(buf, "atime", &def->timestamps->atime); + virStorageVolTimestampFormat(buf, "mtime", &def->timestamps->mtime); + virStorageVolTimestampFormat(buf, "ctime", &def->timestamps->ctime); + virStorageVolTimestampFormat(buf, "btime", &def->timestamps->btime); + virBufferAddLit(buf, " \n"); + } + if (def->encryption) { virBufferAdjustIndent(buf, 4); if (virStorageEncryptionFormat(buf, def->encryption) < 0) diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 8c4b202b98..4fb99df278 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -46,6 +46,18 @@ struct _virStoragePerms { /* Storage volumes */ +typedef struct _virStorageTimestamps virStorageTimestamps; +typedef virStorageTimestamps *virStorageTimestampsPtr; +struct _virStorageTimestamps { + struct timespec atime; + /* if btime.tv_nsec == -1 then + * birth time is unknown + */ + struct timespec btime; + struct timespec ctime; + struct timespec mtime; +}; + /* * How the volume's data is stored on underlying @@ -77,6 +89,7 @@ struct _virStorageVolTarget { char *path; int format; virStoragePerms perms; + virStorageTimestampsPtr timestamps; int type; /* only used by disk backend for partition type */ /* Currently used only in virStorageVolDef.target, not in .backingstore. */ virStorageEncryptionPtr encryption; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index e677cda1ae..4a2109e809 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1,7 +1,7 @@ /* * storage_backend.c: internal storage driver backend contract * - * Copyright (C) 2007-2011 Red Hat, Inc. + * Copyright (C) 2007-2012 Red Hat, Inc. * Copyright (C) 2007-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -57,6 +57,7 @@ #include "storage_backend.h" #include "logging.h" #include "virfile.h" +#include "stat-time.h" #if WITH_STORAGE_LVM # include "storage_backend_logical.h" @@ -1214,6 +1215,15 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, target->perms.uid = sb.st_uid; target->perms.gid = sb.st_gid; + if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) { + virReportOOMError(); + return -1; + } + target->timestamps->atime = get_stat_atime(&sb); + target->timestamps->btime = get_stat_birthtime(&sb); + target->timestamps->ctime = get_stat_ctime(&sb); + target->timestamps->mtime = get_stat_mtime(&sb); + VIR_FREE(target->perms.label); #if HAVE_SELINUX diff --git a/tests/storagevolxml2xmlin/vol-file.xml b/tests/storagevolxml2xmlin/vol-file.xml index fdca510101..d3f65f654b 100644 --- a/tests/storagevolxml2xmlin/vol-file.xml +++ b/tests/storagevolxml2xmlin/vol-file.xml @@ -11,5 +11,10 @@ 0 + + 1341933637.273190990 + 1341930622.047245868 + 1341930622.047245868 +