提交 7383c1d7 编写于 作者: H Hendrik Schwartke 提交者: Eric Blake

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: NEric Blake <eblake@redhat.com>
上级 37a10129
......@@ -89,6 +89,7 @@ sigaction
sigpipe
snprintf
socket
stat-time
stdarg
stpcpy
strchrnul
......
......@@ -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
......
......@@ -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>
......
......@@ -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
......
......@@ -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)
......
......@@ -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;
......
/*
* 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
......
......@@ -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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册