diff mbox

[V3,6/7] qcow2: print message for error path in snapshot creation

Message ID 1378695482-29805-7-git-send-email-xiawenc@linux.vnet.ibm.com
State New
Headers show

Commit Message

Wayne Xia Sept. 9, 2013, 2:58 a.m. UTC
The message will be print out with a macro enabled, which can
be used to check which error path is taken.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 block/qcow2-snapshot.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

Comments

Eric Blake Sept. 30, 2013, 10:08 p.m. UTC | #1
On 09/08/2013 08:58 PM, Wenchao Xia wrote:
> The message will be print out with a macro enabled, which can

s/print/printed/

> be used to check which error path is taken.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  block/qcow2-snapshot.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 46 insertions(+), 0 deletions(-)
> 

> @@ -381,12 +413,20 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
>      ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
>              sn->l1_table_offset, s->l1_size * sizeof(uint64_t));
>      if (ret < 0) {
> +#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
> +        printf("qcow2: Failed in overlap check before update L1 table for "
> +               "snapshot\n");
> +#endif
>          goto dealloc_cluster;
>      }
>  
> +    BLKDBG_EVENT(bs->file, BLKDBG_SNAPSHOT_L1_UPDATE);

Should this BLKDBG be part of patch 5?

In general, the move to avoid fprintf except under recompilation seems
okay; but it seems odd to be removing the diagnosis altogether.  If you
had gone one step further and refactored the code to wire in Error*
support, then you could change fprintf to passing the Error back up the
stack to the caller rather than losing it except during a debug build.
Stefan Hajnoczi Oct. 2, 2013, 12:23 p.m. UTC | #2
On Mon, Sep 30, 2013 at 04:08:53PM -0600, Eric Blake wrote:
> On 09/08/2013 08:58 PM, Wenchao Xia wrote:
> > The message will be print out with a macro enabled, which can
> 
> s/print/printed/
> 
> > be used to check which error path is taken.
> > 
> > Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> > ---
> >  block/qcow2-snapshot.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 files changed, 46 insertions(+), 0 deletions(-)
> > 
> 
> > @@ -381,12 +413,20 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
> >      ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
> >              sn->l1_table_offset, s->l1_size * sizeof(uint64_t));
> >      if (ret < 0) {
> > +#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
> > +        printf("qcow2: Failed in overlap check before update L1 table for "
> > +               "snapshot\n");
> > +#endif
> >          goto dealloc_cluster;
> >      }
> >  
> > +    BLKDBG_EVENT(bs->file, BLKDBG_SNAPSHOT_L1_UPDATE);
> 
> Should this BLKDBG be part of patch 5?
> 
> In general, the move to avoid fprintf except under recompilation seems
> okay; but it seems odd to be removing the diagnosis altogether.  If you
> had gone one step further and refactored the code to wire in Error*
> support, then you could change fprintf to passing the Error back up the
> stack to the caller rather than losing it except during a debug build.

I agree with Eric.  Use Error* and make snapshot commands print a
detailed error to the monitor.

When diagnostics are compiled out we can't help troubleshoot user
problems.

Stefan
Wayne Xia Oct. 14, 2013, 7:39 a.m. UTC | #3
于 2013/10/2 20:23, Stefan Hajnoczi 写道:
> On Mon, Sep 30, 2013 at 04:08:53PM -0600, Eric Blake wrote:
>> On 09/08/2013 08:58 PM, Wenchao Xia wrote:
>>> The message will be print out with a macro enabled, which can
>> s/print/printed/
>>
>>> be used to check which error path is taken.
>>>
>>> Signed-off-by: Wenchao Xia<xiawenc@linux.vnet.ibm.com>
>>> ---
>>>   block/qcow2-snapshot.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>>>   1 files changed, 46 insertions(+), 0 deletions(-)
>>>
>>> @@ -381,12 +413,20 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
>>>       ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
>>>               sn->l1_table_offset, s->l1_size * sizeof(uint64_t));
>>>       if (ret<  0) {
>>> +#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
>>> +        printf("qcow2: Failed in overlap check before update L1 table for "
>>> +               "snapshot\n");
>>> +#endif
>>>           goto dealloc_cluster;
>>>       }
>>>
>>> +    BLKDBG_EVENT(bs->file, BLKDBG_SNAPSHOT_L1_UPDATE);
>> Should this BLKDBG be part of patch 5?
>>
>> In general, the move to avoid fprintf except under recompilation seems
>> okay; but it seems odd to be removing the diagnosis altogether.  If you
>> had gone one step further and refactored the code to wire in Error*
>> support, then you could change fprintf to passing the Error back up the
>> stack to the caller rather than losing it except during a debug build.
> I agree with Eric.  Use Error* and make snapshot commands print a
> detailed error to the monitor.
>
> When diagnostics are compiled out we can't help troubleshoot user
> problems.
>
> Stefan
>
Make sense, will add *errp to report the errors.
diff mbox

Patch

diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 92b87f8..7f24486 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -26,6 +26,8 @@ 
 #include "block/block_int.h"
 #include "block/qcow2.h"
 
+/* #define QCOW2_SNAPSHOT_PRINT_ERROR_PATH */
+
 typedef struct QEMU_PACKED QCowSnapshotHeader {
     /* header is 8 byte aligned */
     uint64_t l1_table_offset;
@@ -182,10 +184,16 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
     snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
     offset = snapshots_offset;
     if (offset < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in allocation of snapshot list\n");
+#endif
         return offset;
     }
     ret = bdrv_flush(bs);
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in flush after snapshot list allocation\n");
+#endif
         goto fail;
     }
 
@@ -194,6 +202,9 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
     ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT, offset,
                                         s->snapshots_size);
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in overlap check before update snapshot list\n");
+#endif
         goto fail;
     }
 
@@ -227,24 +238,36 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
 
         ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h));
         if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+            printf("qcow2: Failed in update of snapshot header\n");
+#endif
             goto fail;
         }
         offset += sizeof(h);
 
         ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra));
         if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+            printf("qcow2: Failed in update of extra snapshot info\n");
+#endif
             goto fail;
         }
         offset += sizeof(extra);
 
         ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size);
         if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+            printf("qcow2: Failed in update of snapshot id\n");
+#endif
             goto fail;
         }
         offset += id_str_size;
 
         ret = bdrv_pwrite(bs->file, offset, sn->name, name_size);
         if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+            printf("qcow2: Failed in update of snapshot name\n");
+#endif
             goto fail;
         }
         offset += name_size;
@@ -256,6 +279,9 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
      */
     ret = bdrv_flush(bs);
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in flush after update snapshot list\n");
+#endif
         goto fail;
     }
 
@@ -269,6 +295,9 @@  static int qcow2_write_snapshots(BlockDriverState *bs)
     ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
                            &header_data, sizeof(header_data));
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in update qcow2 header in snapshot creation\n");
+#endif
         goto fail;
     }
 
@@ -366,6 +395,9 @@  int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
     l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
     if (l1_table_offset < 0) {
         ret = l1_table_offset;
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in allocation of L1 table for snapshot\n");
+#endif
         goto fail;
     }
 
@@ -381,12 +413,20 @@  int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
     ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT,
             sn->l1_table_offset, s->l1_size * sizeof(uint64_t));
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in overlap check before update L1 table for "
+               "snapshot\n");
+#endif
         goto dealloc_cluster;
     }
 
+    BLKDBG_EVENT(bs->file, BLKDBG_SNAPSHOT_L1_UPDATE);
     ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,
                       s->l1_size * sizeof(uint64_t));
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in update of L1 table for snapshot\n");
+#endif
         goto dealloc_cluster;
     }
 
@@ -400,6 +440,9 @@  int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
      */
     ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
     if (ret < 0) {
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in update refcount for snapshot\n");
+#endif
         goto dealloc_cluster;
     }
 
@@ -419,6 +462,9 @@  int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
         g_free(s->snapshots);
         s->snapshots = old_snapshot_list;
         s->nb_snapshots = old_snapshot_num;
+#ifdef QCOW2_SNAPSHOT_PRINT_ERROR_PATH
+        printf("qcow2: Failed in update of snapshot list and header\n");
+#endif
         goto restore_refcount;
     }