Re: [libvirt] [PATCH 6/7] Break out FS volume build routines to their own functions.

2009-05-12 Thread Cole Robinson
On 05/11/2009 08:58 AM, Daniel P. Berrange wrote:
 On Mon, May 04, 2009 at 01:43:01PM -0400, Cole Robinson wrote:
 Improves readability, particularly wrt the pending CreateFromXML changes.
 This will also help implementing File-Block volume creation in the future,
 since some of this code will need to be moved to a backend agnostic file.
 
 This is a nice idea - it was getting rather unwieldly as it grew.
 
 ACK.
 
 Daniel
 

Since this is a mechanical change separate from the VolCreateXMLFrom
implementation, I've committed this.

Thanks,
Cole

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


Re: [libvirt] [PATCH 6/7] Break out FS volume build routines to their own functions.

2009-05-11 Thread Daniel P. Berrange
On Mon, May 04, 2009 at 01:43:01PM -0400, Cole Robinson wrote:
 Improves readability, particularly wrt the pending CreateFromXML changes.
 This will also help implementing File-Block volume creation in the future,
 since some of this code will need to be moved to a backend agnostic file.

This is a nice idea - it was getting rather unwieldly as it grew.

ACK.

Daniel

 
 Signed-off-by: Cole Robinson crobi...@redhat.com
 ---
  src/storage_backend_fs.c |  327 
 +-
  1 files changed, 179 insertions(+), 148 deletions(-)
 
 diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
 index 7a1bba8..241fb29 100644
 --- a/src/storage_backend_fs.c
 +++ b/src/storage_backend_fs.c
 @@ -62,6 +62,8 @@ static int qcowXGetBackingStore(virConnectPtr, char **,
  static int vmdk4GetBackingStore(virConnectPtr, char **,
  const unsigned char *, size_t);
  
 +typedef int (*createFile)(virConnectPtr conn, virStorageVolDefPtr vol);
 +
  static int track_allocation_progress = 0;
  
  /* Either 'magic' or 'extension' *must* be provided */
 @@ -1011,183 +1013,202 @@ virStorageBackendFileSystemVolCreate(virConnectPtr 
 conn,
  return 0;
  }
  
 -/**
 - * Allocate a new file as a volume. This is either done directly
 - * for raw/sparse files, or by calling qemu-img/qcow-create for
 - * special kinds of files
 - */
 -static int
 -virStorageBackendFileSystemVolBuild(virConnectPtr conn,
 -virStorageVolDefPtr vol)
 -{
 +// XXX: Have these functions all use the same format?
 +static int createRaw(virConnectPtr conn,
 + virStorageVolDefPtr vol) {
  int fd;
  
 -if (vol-target.format == VIR_STORAGE_VOL_FILE_RAW) {
 -if ((fd = open(vol-target.path, O_RDWR | O_CREAT | O_EXCL,
 -   vol-target.perms.mode))  0) {
 -virReportSystemError(conn, errno,
 - _(cannot create path '%s'),
 - vol-target.path);
 -return -1;
 -}
 +if ((fd = open(vol-target.path, O_RDWR | O_CREAT | O_EXCL,
 +   vol-target.perms.mode))  0) {
 +virReportSystemError(conn, errno,
 + _(cannot create path '%s'),
 + vol-target.path);
 +return -1;
 +}
  
 -/* Seek to the final size, so the capacity is available upfront
 - * for progress reporting */
 -if (ftruncate(fd, vol-capacity)  0) {
 -virReportSystemError(conn, errno,
 - _(cannot extend file '%s'),
 - vol-target.path);
 -close(fd);
 -return -1;
 -}
 +/* Seek to the final size, so the capacity is available upfront
 + * for progress reporting */
 +if (ftruncate(fd, vol-capacity)  0) {
 +virReportSystemError(conn, errno,
 + _(cannot extend file '%s'),
 + vol-target.path);
 +close(fd);
 +return -1;
 +}
  
 -/* Pre-allocate any data if requested */
 -/* XXX slow on non-extents-based file systems */
 -/* FIXME: Add in progress bars  bg thread if progress bar requested 
 */
 -if (vol-allocation) {
 -if (track_allocation_progress) {
 -unsigned long long remain = vol-allocation;
 -
 -while (remain) {
 -/* Allocate in chunks of 512MiB: big-enough chunk
 - * size and takes approx. 9s on ext3. A progress
 - * update every 9s is a fair-enough trade-off
 - */
 -unsigned long long bytes = 512 * 1024 * 1024;
 -int r;
 -
 -if (bytes  remain)
 -bytes = remain;
 -if ((r = safezero(fd, 0, vol-allocation - remain,
 -  bytes)) != 0) {
 -virReportSystemError(conn, r,
 - _(cannot fill file '%s'),
 - vol-target.path);
 -close(fd);
 -return -1;
 -}
 -remain -= bytes;
 -}
 -} else { /* No progress bars to be shown */
 +/* Pre-allocate any data if requested */
 +/* XXX slow on non-extents-based file systems */
 +if (vol-allocation) {
 +if (track_allocation_progress) {
 +unsigned long long remain = vol-allocation;
 +
 +while (remain) {
 +/* Allocate in chunks of 512MiB: big-enough chunk
 + * size and takes approx. 9s on ext3. A progress
 + * update every 9s is a fair-enough trade-off
 + */
 +unsigned 

[libvirt] [PATCH 6/7] Break out FS volume build routines to their own functions.

2009-05-04 Thread Cole Robinson
Improves readability, particularly wrt the pending CreateFromXML changes.
This will also help implementing File-Block volume creation in the future,
since some of this code will need to be moved to a backend agnostic file.

Signed-off-by: Cole Robinson crobi...@redhat.com
---
 src/storage_backend_fs.c |  327 +-
 1 files changed, 179 insertions(+), 148 deletions(-)

diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
index 7a1bba8..241fb29 100644
--- a/src/storage_backend_fs.c
+++ b/src/storage_backend_fs.c
@@ -62,6 +62,8 @@ static int qcowXGetBackingStore(virConnectPtr, char **,
 static int vmdk4GetBackingStore(virConnectPtr, char **,
 const unsigned char *, size_t);
 
+typedef int (*createFile)(virConnectPtr conn, virStorageVolDefPtr vol);
+
 static int track_allocation_progress = 0;
 
 /* Either 'magic' or 'extension' *must* be provided */
@@ -1011,183 +1013,202 @@ virStorageBackendFileSystemVolCreate(virConnectPtr 
conn,
 return 0;
 }
 
-/**
- * Allocate a new file as a volume. This is either done directly
- * for raw/sparse files, or by calling qemu-img/qcow-create for
- * special kinds of files
- */
-static int
-virStorageBackendFileSystemVolBuild(virConnectPtr conn,
-virStorageVolDefPtr vol)
-{
+// XXX: Have these functions all use the same format?
+static int createRaw(virConnectPtr conn,
+ virStorageVolDefPtr vol) {
 int fd;
 
-if (vol-target.format == VIR_STORAGE_VOL_FILE_RAW) {
-if ((fd = open(vol-target.path, O_RDWR | O_CREAT | O_EXCL,
-   vol-target.perms.mode))  0) {
-virReportSystemError(conn, errno,
- _(cannot create path '%s'),
- vol-target.path);
-return -1;
-}
+if ((fd = open(vol-target.path, O_RDWR | O_CREAT | O_EXCL,
+   vol-target.perms.mode))  0) {
+virReportSystemError(conn, errno,
+ _(cannot create path '%s'),
+ vol-target.path);
+return -1;
+}
 
-/* Seek to the final size, so the capacity is available upfront
- * for progress reporting */
-if (ftruncate(fd, vol-capacity)  0) {
-virReportSystemError(conn, errno,
- _(cannot extend file '%s'),
- vol-target.path);
-close(fd);
-return -1;
-}
+/* Seek to the final size, so the capacity is available upfront
+ * for progress reporting */
+if (ftruncate(fd, vol-capacity)  0) {
+virReportSystemError(conn, errno,
+ _(cannot extend file '%s'),
+ vol-target.path);
+close(fd);
+return -1;
+}
 
-/* Pre-allocate any data if requested */
-/* XXX slow on non-extents-based file systems */
-/* FIXME: Add in progress bars  bg thread if progress bar requested */
-if (vol-allocation) {
-if (track_allocation_progress) {
-unsigned long long remain = vol-allocation;
-
-while (remain) {
-/* Allocate in chunks of 512MiB: big-enough chunk
- * size and takes approx. 9s on ext3. A progress
- * update every 9s is a fair-enough trade-off
- */
-unsigned long long bytes = 512 * 1024 * 1024;
-int r;
-
-if (bytes  remain)
-bytes = remain;
-if ((r = safezero(fd, 0, vol-allocation - remain,
-  bytes)) != 0) {
-virReportSystemError(conn, r,
- _(cannot fill file '%s'),
- vol-target.path);
-close(fd);
-return -1;
-}
-remain -= bytes;
-}
-} else { /* No progress bars to be shown */
+/* Pre-allocate any data if requested */
+/* XXX slow on non-extents-based file systems */
+if (vol-allocation) {
+if (track_allocation_progress) {
+unsigned long long remain = vol-allocation;
+
+while (remain) {
+/* Allocate in chunks of 512MiB: big-enough chunk
+ * size and takes approx. 9s on ext3. A progress
+ * update every 9s is a fair-enough trade-off
+ */
+unsigned long long bytes = 512 * 1024 * 1024;
 int r;
 
-if ((r = safezero(fd, 0, 0, vol-allocation)) != 0) {
+if (bytes  remain)
+bytes = remain;
+if ((r = safezero(fd, 0, vol-allocation -