[libvirt] [PATCH 1/7] Add virFileTouch for creating empty files
Eric Blake
eblake at redhat.com
Mon Jan 23 22:16:20 UTC 2012
On 01/11/2012 09:33 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange at redhat.com>
>
> Add a virFileTouch API which ensures that a file will always
> exist, even if zero length
>
> * src/lxc/lxc_container.c, src/util/virfile.h: virFileTouch
This line is not quite accurate,
> ---
> src/util/virfile.c | 21 +++++++++++++++++++++
> src/util/virfile.h | 2 ++
> 2 files changed, 23 insertions(+), 0 deletions(-)
to this diffstat (drop lxc_container). Otherwise, looks like a useful API.
>
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index cbc3fcc..e6b469c 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -390,3 +390,24 @@ cleanup:
> }
> return ret;
> }
> +
> +
> +int virFileTouch(const char *path, mode_t mode)
> +{
> + int fd = -1;
> +
> + if ((fd = open(path, O_WRONLY | O_CREAT, mode)) < 0) {
> + virReportSystemError(errno, _("cannot create file '%s'"),
> + path);
> + return -1;
Should we be using virFileOpenAs() for the sake of touching a file with
different permissions on a root-squash NFS server?
In particular, I wonder if any of qemu_driver.c could reuse this
function, if it were to use virFileOpenAs() - for example, creating a
qemu snapshot requires that a file already exist and be empty before
making the monitor call.
ACK - any change to use virFileOpenAs can come as a later patch.
--
Eric Blake eblake at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120123/72489721/attachment-0001.sig>
More information about the libvir-list
mailing list