]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Added timestamps to storage volumes
authorHendrik Schwartke <hendrik@os-t.de>
Wed, 25 Jul 2012 07:43:37 +0000 (09:43 +0200)
committerEric Blake <eblake@redhat.com>
Thu, 2 Aug 2012 23:14:17 +0000 (17:14 -0600)
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>
bootstrap.conf
docs/formatstorage.html.in
docs/schemas/storagevol.rng
m4/virt-compile-warnings.m4
src/conf/storage_conf.c
src/conf/storage_conf.h
src/storage/storage_backend.c
tests/storagevolxml2xmlin/vol-file.xml

index 66a88cda7b0240d2596335677d890ed848299672..c112ccd8a889e72ed0dd0723180eac836d5c3cac 100644 (file)
@@ -89,6 +89,7 @@ sigaction
 sigpipe
 snprintf
 socket
+stat-time
 stdarg
 stpcpy
 strchrnul
index d0e4319c509dcb00ec6dc38e31c54025c191a757..9f93db810a7b0533566fc8c990fb029a4f80bb3b 100644 (file)
             &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;
         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
index 0b9933d56c057ff5e1adf6241bcc91759010ac3d..8335b616fd683c41e2926feb634e2a6553efad10 100644 (file)
     </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>
       </optional>
       <ref name='format'/>
       <ref name='permissions'/>
+      <ref name='timestamps'/>
       <optional>
         <ref name='encryption'/>
       </optional>
index 18170474d791d8cf73846214bacfa0c1a8c744cb..9dee000f6b16b2ffa38834637bb91d2e1904a62f 100644 (file)
@@ -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
index b07a7aa0b30acac1575e8f55dee13669c47f8edb..3132aae3baf5be2bbd9629f8731354c0b6ec1c4b 100644 (file)
@@ -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)
index 8c4b202b989758535fa9f397d157c41343ebdd47..4fb99df27888174cf88b09e102343ef9cd47dd00 100644 (file)
@@ -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;
index e677cda1ae68485a4d7f9a94421b512c35cc642d..4a2109e80945b89a5c20a2b77ec755bd233d5de5 100644 (file)
@@ -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
index fdca510101f3608210fc92e55bfe5882059d0599..d3f65f654b975ad1648e00a09b4ec194a94837f0 100644 (file)
       <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>