[libvirt] [PATCH] Added timestamps to storage volumes

Hendrik Schwartke hendrik at os-t.de
Tue Jul 10 15:22:22 UTC 2012


The access, modification and change times are added to storage
volumes and corresponding xml representations.
---
 docs/formatstorage.html.in    |   13 +++++++++++++
 docs/schemas/storagevol.rng   |   23 +++++++++++++++++++++++
 src/conf/storage_conf.c       |   12 ++++++++++++
 src/conf/storage_conf.h       |    9 +++++++++
 src/storage/storage_backend.c |   20 ++++++++++++++++++++
 5 files changed, 77 insertions(+)

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index d0e4319..c4d6d85 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.27319099</atime>
+            <mtime>1341930622.47245868</mtime>
+            <ctime>1341930622.47245868</ctime>
+          </timestamps>
           <encryption type='...'>
             ...
           </encryption>
@@ -172,6 +177,14 @@
         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. The three sub elements
+        <code>atime</code>, <code>mtime</code> and <code>ctime</code> hold the
+        access, modification and respectively the change time of the volume. The
+        used time format is <seconds>.<nanoseconds> since the beginning
+        of the epoch.  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 7a74331..dafe918 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -63,6 +63,28 @@
     </optional>
   </define>
 
+  <define name='timestamps'>
+    <optional>
+      <element name='timestamps'>
+        <element name='atime'>
+          <data type="string">
+            <param name="pattern">[0-9]+\.[0-9]+</param>
+          </data>
+        </element>
+        <element name='mtime'>
+          <data type="string">
+            <param name="pattern">[0-9]+\.[0-9]+</param>
+          </data>
+        </element>
+        <element name='ctime'>
+          <data type="string">
+            <param name="pattern">[0-9]+\.[0-9]+</param>
+          </data>
+        </element>
+      </element>
+    </optional>
+  </define>
+
   <define name='target'>
     <element name='target'>
       <optional>
@@ -72,6 +94,7 @@
       </optional>
       <ref name='format'/>
       <ref name='permissions'/>
+      <ref name='timestamps'/>
       <optional>
         <ref name='encryption'/>
       </optional>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ab8df9e..435ad00 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1272,6 +1272,18 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
 
     virBufferAddLit(buf,"    </permissions>\n");
 
+    virBufferAddLit(buf, "    <timestamps>\n");
+    virBufferAsprintf(buf, "      <atime>%llu.%lu</atime>\n",
+                      (unsigned long long) def->timestamps.atime.tv_sec,
+                      def->timestamps.atime.tv_nsec);
+    virBufferAsprintf(buf, "      <mtime>%llu.%lu</mtime>\n",
+                      (unsigned long long) def->timestamps.mtime.tv_sec,
+                      def->timestamps.mtime.tv_nsec);
+    virBufferAsprintf(buf, "      <ctime>%llu.%lu</ctime>\n",
+                      (unsigned long long) def->timestamps.ctime.tv_sec,
+                      def->timestamps.ctime.tv_nsec);
+    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 5733b57..977b136 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -46,6 +46,14 @@ struct _virStoragePerms {
 
 /* Storage volumes */
 
+typedef struct _virStorageTimestamps virStorageTimestamps;
+typedef virStorageTimestamps *virStorageTimestampsPtr;
+struct _virStorageTimestamps {
+    struct timespec atime;
+    struct timespec mtime;
+    struct timespec ctime;
+};
+
 
 /*
  * How the volume's data is stored on underlying
@@ -77,6 +85,7 @@ struct _virStorageVolTarget {
     char *path;
     int format;
     virStoragePerms perms;
+    virStorageTimestamps 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 e2e9b51..ce4d808 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1156,6 +1156,9 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
                                        unsigned long long *capacity)
 {
     struct stat sb;
+    struct timespec *const atime=&target->timestamps.atime,
+                    *const mtime=&target->timestamps.mtime,
+                    *const catime=&target->timestamps.ctime;
 #if HAVE_SELINUX
     security_context_t filecon = NULL;
 #endif
@@ -1209,6 +1212,23 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
     target->perms.uid = sb.st_uid;
     target->perms.gid = sb.st_gid;
 
+    atime->tv_sec = sb.st_atime;
+    mtime->tv_sec = sb.st_mtime;
+    catime->tv_sec = sb.st_ctime;
+#if _BSD_SOURCE || _SVID_SOURCE
+    atime->tv_nsec = sb.st_atim.tv_nsec;
+    mtime->tv_nsec = sb.st_mtim.tv_nsec;
+    catime->tv_nsec = sb.st_ctim.tv_nsec;
+#elif _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
+    atime->tv_nsec = sb.st_atimensec;
+    mtime->tv_nsec = sb.st_mtimensec;
+    catime->tv_nsec = sb.st_ctimensec;
+#else
+    atime->tv_nsec = 0;
+    mtime->tv_nsec = 0;
+    catime->tv_nsec = 0;
+#endif
+
     VIR_FREE(target->perms.label);
 
 #if HAVE_SELINUX
-- 
1.7.9.5




More information about the libvir-list mailing list