[PATCH] Added timestamps to storage volumes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



!!! DON'T PUSH until stat-time lgpl 3 issue is fixed
!!! To tests this change lgpl version to 3 in bootstrap.conf:176

The access, birth, modification and change times are added to
storage volumes and corresponding xml representations.
---
 bootstrap.conf                |    1 +
 docs/formatstorage.html.in    |   13 +++++++++++++
 docs/schemas/storagevol.rng   |   36 ++++++++++++++++++++++++++++++++++++
 src/conf/storage_conf.c       |   18 ++++++++++++++++++
 src/conf/storage_conf.h       |   13 +++++++++++++
 src/storage/storage_backend.c |    6 ++++++
 6 files changed, 87 insertions(+)

diff --git a/bootstrap.conf b/bootstrap.conf
index 9b42cbf..da0b960 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -115,6 +115,7 @@ vc-list-files
 vsnprintf
 waitpid
 warnings
+stat-time
 '
 
 # Additional xgettext options to use.  Use "\\\newline" to break lines.
diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index d0e4319..ec7ec90 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>
+            <ctime>1341930622.47245868</ctime>
+            <mtime>1341930622.47245868</mtime>
+          </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 four sub elements
+        <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.  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..a20c7a5 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -63,6 +63,41 @@
     </optional>
   </define>
 
+  <define name='timestamps'>
+    <optional>
+      <element name='timestamps'>
+        <optional>
+          <element name='atime'>
+            <data type="string">
+              <param name="pattern">[0-9]+\.[0-9]+</param>
+            </data>
+          </element>
+        </optional>
+        <optional>
+          <element name='btime'>
+            <data type="string">
+              <param name="pattern">[0-9]+\.[0-9]+</param>
+            </data>
+          </element>
+        </optional>
+        <optional>
+          <element name='ctime'>
+            <data type="string">
+              <param name="pattern">[0-9]+\.[0-9]+</param>
+            </data>
+          </element>
+        </optional>
+        <optional>
+          <element name='mtime'>
+            <data type="string">
+              <param name="pattern">[0-9]+\.[0-9]+</param>
+            </data>
+          </element>
+        </optional>
+      </element>
+    </optional>
+  </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/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 36a3bb9..b1ec8da 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1277,6 +1277,24 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
 
     virBufferAddLit(buf,"    </permissions>\n");
 
+    virBufferAddLit(buf, "    <timestamps>\n");
+    virBufferAsprintf(buf, "      <atime>%llu.%ld</atime>\n",
+                      (unsigned long long) def->timestamps.atime.tv_sec,
+                      def->timestamps.atime.tv_nsec);
+    if(def->timestamps.btime.tv_sec != -1 ||
+       def->timestamps.btime.tv_nsec != -1) {
+        virBufferAsprintf(buf, "      <btime>%llu.%ld</btime>\n",
+                          (unsigned long long) def->timestamps.btime.tv_sec,
+                          def->timestamps.btime.tv_nsec);
+    }
+    virBufferAsprintf(buf, "      <ctime>%llu.%ld</ctime>\n",
+                      (unsigned long long) def->timestamps.ctime.tv_sec,
+                      def->timestamps.ctime.tv_nsec);
+    virBufferAsprintf(buf, "      <mtime>%llu.%ld</mtime>\n",
+                      (unsigned long long) def->timestamps.mtime.tv_sec,
+                      def->timestamps.mtime.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..706e874 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_sec == -1 && btime.tv_nsec == -1 than
+     * 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;
+    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 6ea0881..c665711 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -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"
@@ -1208,6 +1209,11 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
     target->perms.uid = sb.st_uid;
     target->perms.gid = sb.st_gid;
 
+    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
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]