summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHendrik Schwartke <hendrik@os-t.de>2012-07-25 09:43:37 +0200
committerEric Blake <eblake@redhat.com>2012-08-02 17:14:17 -0600
commit7383c1d762c50c83832a8d11b48d75e5cad0042a (patch)
tree80b951133c79a4c9898c1f9c460dbe9218458720
parentUpdate xml schemas according to libvirt source (diff)
downloadlibvirt-7383c1d762c50c83832a8d11b48d75e5cad0042a.tar.gz
libvirt-7383c1d762c50c83832a8d11b48d75e5cad0042a.tar.bz2
libvirt-7383c1d762c50c83832a8d11b48d75e5cad0042a.zip
Added timestamps to storage volumes
The access, birth, modification and change times are added to storage volumes and corresponding xml representations. This shows up in the XML in this format: <timestamps> <atime>1341933637.027319099</atime> <mtime>1341933637.027319099</mtime> </timestamps> Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r--bootstrap.conf1
-rw-r--r--docs/formatstorage.html.in18
-rw-r--r--docs/schemas/storagevol.rng36
-rw-r--r--m4/virt-compile-warnings.m42
-rw-r--r--src/conf/storage_conf.c24
-rw-r--r--src/conf/storage_conf.h13
-rw-r--r--src/storage/storage_backend.c12
-rw-r--r--tests/storagevolxml2xmlin/vol-file.xml5
8 files changed, 110 insertions, 1 deletions
diff --git a/bootstrap.conf b/bootstrap.conf
index 66a88cda7..c112ccd8a 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 d0e4319c5..9f93db810 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -141,6 +141,11 @@
&lt;mode&gt;0744&lt;/mode&gt;
&lt;label&gt;virt_image_t&lt;/label&gt;
&lt;/permissions&gt;
+ &lt;timestamps&gt;
+ &lt;atime&gt;1341933637.273190990&lt;/atime&gt;
+ &lt;mtime&gt;1341930622.047245868&lt;/mtime&gt;
+ &lt;ctime&gt;1341930622.047245868&lt;/ctime&gt;
+ &lt;/timestamps&gt;
&lt;encryption type='...'&gt;
...
&lt;/encryption&gt;
@@ -172,6 +177,19 @@
contains the MAC (eg SELinux) label string.
<span class="since">Since 0.4.1</span>
</dd>
+ <dt><code>timestamps</code></dt>
+ <dd>Provides timing information about the volume. Up to four
+ sub-elements are present,
+ where <code>atime</code>, <code>btime</code>, <code>ctime</code>
+ and <code>mtime</code> hold the access, birth, change and
+ modification time of the volume, where known. The used time
+ format is &lt;seconds&gt;.&lt;nanoseconds&gt; 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.
+ <span class="since">Since 0.10.0</span>
+ </dd>
<dt><code>encryption</code></dt>
<dd>If present, specifies how the volume is encrypted. See
the <a href="formatstorageencryption.html">Storage Encryption</a> page
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 0b9933d56..8335b616f 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -63,6 +63,41 @@
</optional>
</define>
+ <define name='timestamps'>
+ <optional>
+ <element name='timestamps'>
+ <interleave>
+ <optional>
+ <element name='atime'>
+ <ref name='timestamp'/>
+ </element>
+ </optional>
+ <optional>
+ <element name='btime'>
+ <ref name='timestamp'/>
+ </element>
+ </optional>
+ <optional>
+ <element name='ctime'>
+ <ref name='timestamp'/>
+ </element>
+ </optional>
+ <optional>
+ <element name='mtime'>
+ <ref name='timestamp'/>
+ </element>
+ </optional>
+ </interleave>
+ </element>
+ </optional>
+ </define>
+
+ <define name='timestamp'>
+ <data type='string'>
+ <param name="pattern">[0-9]+(\.[0-9]{0,9})?</param>
+ </data>
+ </define>
+
<define name='target'>
<element name='target'>
<optional>
@@ -72,6 +107,7 @@
</optional>
<ref name='format'/>
<ref name='permissions'/>
+ <ref name='timestamps'/>
<optional>
<ref name='encryption'/>
</optional>
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 18170474d..9dee000f6 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 b07a7aa0b..3132aae3b 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, "</%s>\n", name);
+}
+
static int
virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
virBufferPtr buf,
@@ -1288,6 +1303,15 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
virBufferAddLit(buf," </permissions>\n");
+ if (def->timestamps) {
+ virBufferAddLit(buf, " <timestamps>\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, " </timestamps>\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 8c4b202b9..4fb99df27 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 e677cda1a..4a2109e80 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 fdca51010..d3f65f654 100644
--- a/tests/storagevolxml2xmlin/vol-file.xml
+++ b/tests/storagevolxml2xmlin/vol-file.xml
@@ -11,5 +11,10 @@
<group>0</group>
<label>virt_image_t</label>
</permissions>
+ <timestamps>
+ <atime>1341933637.273190990</atime>
+ <mtime>1341930622.047245868</mtime>
+ <ctime>1341930622.047245868</ctime>
+ </timestamps>
</target>
</volume>