[libvirt] [PATCH v2 01/13] util: add APIs for reading/writing from/to rotating files

Peter Krempa pkrempa at redhat.com
Wed Nov 18 12:57:45 UTC 2015


On Thu, Nov 12, 2015 at 17:18:58 +0000, Daniel Berrange wrote:
> Add virRotatingFileReader and virRotatingFileWriter objects
> which allow reading & writing from/to files with automation
> rotation to N backup files when a size limit is reached. This
> is useful for guest logging when a guaranteed finite size
> limit is required. Use of external tools like logrotate is
> inadequate since it leaves the possibility for guest to DOS
> the host in between invokations of logrotate.
> 
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---

[...]

> diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
> new file mode 100644
> index 0000000..840b55f
> --- /dev/null
> +++ b/src/util/virrotatingfile.c
> @@ -0,0 +1,608 @@

[...]

> +
> +
> +/**
> + * virRotatingFileWriterGetPath:
> + * @file: the file context
> + *
> + * Return the primary file path
> + */
> +const char *virRotatingFileWriterGetPath(virRotatingFileWriterPtr file)
> +{
> +    return file->basepath;
> +}
> +
> +
> +/**
> + * virRotatingFileWriterGetINode:
> + * @file: the file context
> + *
> + * Return the inode of the file currently being written to
> + */
> +ino_t virRotatingFileWriterGetINode(virRotatingFileWriterPtr file)
> +{
> +    return file->entry->inode;
> +}
> +
> +
> +/**
> + * virRotatingFileWriterGetOffset:
> + * @file: the file context
> + *
> + * Return the offset at which data is currently being written
> + */
> +off_t virRotatingFileWriterGetOffset(virRotatingFileWriterPtr file)
> +{
> +    return file->entry->pos;
> +}

I see how you are going to use this. I think the usage pattern is a bit
complicated, but for the purpose it will serve it's probably all right.

ACK

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20151118/f4660e3e/attachment-0001.sig>


More information about the libvir-list mailing list