Skip to contentSkip to conversation

xl: Return proper error codes for block-attach and block-detach

PATCH In review George Dunlap 3 participants 8 messages Nov 13, 2014 – Nov 20, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xl: Return proper error codes for block-attach and block-detach

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Wilk <[email protected]>

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2:
- Restructure functions to make sure init and dispose are properly called.

---
 tools/libxl/libxl.c      |  2 --
 tools/libxl/xl_cmdimpl.c | 28 +++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +0 -2
index f7961f6..d9c4ce7 100644
@@ -2611,8 +2611,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     if (devid < 0)
         return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);
-
     dompath = libxl__xs_get_dompath(gc, domid);
     if (!dompath) {
         goto out;
tools/libxl/xl_cmdimpl.c +21 -7
index 3c9f146..25af715 100644
@@ -485,8 +485,6 @@ static void parse_disk_config_multistring(XLU_Config **config,
 {
     int e;
 
-    libxl_device_disk_init(disk);
-
     if (!*config) {
         *config = xlu_cfg_init(stderr, "command line");
         if (!*config) { perror("xlu_cfg_init"); exit(-1); }
@@ -1405,6 +1403,7 @@ static void parse_config_data(const char *config_source,
 
             d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1));
             disk = d_config->disks + d_config->num_disks;
+            libxl_device_disk_init(disk);
             parse_disk_config(&config, buf2, disk);
 
             free(buf2);
@@ -2931,6 +2930,8 @@ static int cd_insert(uint32_t domid, const char *virtdev, char *phys)
         return 1;
     }
 
+    libxl_device_disk_init(&disk);
+
     parse_disk_config(&config, buf, &disk);
 
     /* ATM the existence of the backing file is not checked for qdisk
@@ -6359,6 +6360,7 @@ int main_blockattach(int argc, char **argv)
     uint32_t fe_domid;
     libxl_device_disk disk;
     XLU_Config *config = 0;
+    int rc = 0;
 
     SWITCH_FOREACH_OPT(opt, "", NULL, "block-attach", 2) {
         /* No options */
@@ -6370,6 +6372,8 @@ int main_blockattach(int argc, char **argv)
     }
     optind++;
 
+    libxl_device_disk_init(&disk);
+
     parse_disk_config_multistring
         (&config, argc-optind, (const char* const*)argv + optind, &disk);
 
@@ -6378,13 +6382,17 @@ int main_blockattach(int argc, char **argv)
         printf("disk: %s\n", json);
         free(json);
         if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-        return 0;
+        goto out;
     }
 
     if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) {
         fprintf(stderr, "libxl_device_disk_add failed.\n");
+        rc = 1;
     }
-    return 0;
+out:
+    libxl_device_disk_dispose(&disk);
+
+    return rc;
 }
 
 int main_blocklist(int argc, char **argv)
@@ -6435,17 +6443,23 @@ int main_blockdetach(int argc, char **argv)
         /* No options */
     }
 
+    libxl_device_disk_init(&disk);
+
     domid = find_domain(argv[optind]);
 
     if (libxl_vdev_to_device_disk(ctx, domid, argv[optind+1], &disk)) {
         fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
-        return 1;
+        rc = 1;
+        goto out;
     }
-    rc = libxl_device_disk_remove(ctx, domid, &disk, 0);
-    if (rc) {
+    if (libxl_device_disk_remove(ctx, domid, &disk, 0)) {
         fprintf(stderr, "libxl_device_disk_remove failed.\n");
+        rc = 1;
     }
+
+out:
     libxl_device_disk_dispose(&disk);
+
     return rc;
 }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 22 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Wilk <[email protected]>

Quoted 6 lines

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2:
- Restructure functions to make sure init and dispose are properly called.

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Quoted 10 lines
---
 tools/libxl/libxl.c      |  2 --
 tools/libxl/xl_cmdimpl.c | 28 +++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +0 -0
index f7961f6..d9c4ce7 100644

tools/libxl/libxl.c int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, · line 2614

Quoted 4 lines
tools/libxl/libxl.c +0 -1
@@ -2611,8 +2611,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
     if (devid < 0)
         return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);

_init functions are idempotent, so this is harmless, I think. Existing callers (including things which aren't xl) might be relying on it. Outside of a freeze period that might be acceptable (those callers are buggy) but since you are asking for a freeze exception I think this may be going a step too far in cleaning things up.

In terms of other callers you've missed tools/ocaml/libs/xl/xenlight_stubs.c (which appears buggy to me) in tree, plus whatever use e.g. libvirt makes of it.

tools/libxl/xl_cmdimpl.c static void parse_disk_config_multistring(XLU_Config **config, · line 488

Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0 -1
index 3c9f146..25af715 100644
@@ -485,8 +485,6 @@ static void parse_disk_config_multistring(XLU_Config **config,
 {
     int e;
 
-    libxl_device_disk_init(disk);

Likewise here, although to a lesser extent since this is xl not libxl.

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6381

Quoted 6 lines
tools/libxl/xl_cmdimpl.c +0 -1
@@ -6378,13 +6382,17 @@ int main_blockattach(int argc, char **argv)
         printf("disk: %s\n", json);
         free(json);
         if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-        return 0;

You should set rc = 0 here rather than initing it at declaration to catch error paths which don't set the result. (we aren't very consistent about this in the code today so I'm only mentioning it because other changes seem to be needed, if that turns out not to be the case and there's no need for v3 then this shouldn't block acceptance)

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6385

Quoted 1 line
tools/libxl/xl_cmdimpl.c +1 -0
+        goto out;

I'm not 100% convinced by the use of the goto out error handling style for a success path, but it's probably better than duplicating the exit path or adding !dryrun checks to all the following operations. Ian, since you recently posted updated coding style for things around this, what do you think?

Ian.

#2 lore raw
Quoted 26 lines · Ian Campbell
Quoted 25 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Wilk <[email protected]>

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

Quoted 7 lines
Quoted 3 lines

v2:
- Restructure functions to make sure init and dispose are properly called.

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Or, if the valgrind thing is really important, I could use the change you suggested, and do "return rc ? 1 : 0;" but I really think that's going in the wrong direction...

-George

Quoted 56 lines
Quoted 11 lines
---
  tools/libxl/libxl.c      |  2 --
  tools/libxl/xl_cmdimpl.c | 28 +++++++++++++++++++++-------
  2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +0 -0
index f7961f6..d9c4ce7 100644

tools/libxl/libxl.c int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, · line 2614

Quoted 4 lines
tools/libxl/libxl.c +0 -1
@@ -2611,8 +2611,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
      if (devid < 0)
          return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);

_init functions are idempotent, so this is harmless, I think. Existing callers (including things which aren't xl) might be relying on it. Outside of a freeze period that might be acceptable (those callers are buggy) but since you are asking for a freeze exception I think this may be going a step too far in cleaning things up.

In terms of other callers you've missed tools/ocaml/libs/xl/xenlight_stubs.c (which appears buggy to me) in tree, plus whatever use e.g. libvirt makes of it.

tools/libxl/xl_cmdimpl.c static void parse_disk_config_multistring(XLU_Config **config, · line 488

Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0 -1
index 3c9f146..25af715 100644
@@ -485,8 +485,6 @@ static void parse_disk_config_multistring(XLU_Config **config,
  {
      int e;
 
-    libxl_device_disk_init(disk);

Likewise here, although to a lesser extent since this is xl not libxl.

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6381

Quoted 6 lines
tools/libxl/xl_cmdimpl.c +0 -1
@@ -6378,13 +6382,17 @@ int main_blockattach(int argc, char **argv)
          printf("disk: %s\n", json);
          free(json);
          if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-        return 0;

You should set rc = 0 here rather than initing it at declaration to catch error paths which don't set the result. (we aren't very consistent about this in the code today so I'm only mentioning it because other changes seem to be needed, if that turns out not to be the case and there's no need for v3 then this shouldn't block acceptance)

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6385

Quoted 1 line
tools/libxl/xl_cmdimpl.c +1 -0
+        goto out;

I'm not 100% convinced by the use of the goto out error handling style for a success path, but it's probably better than duplicating the exit path or adding !dryrun checks to all the following operations. Ian, since you recently posted updated coding style for things around this, what do you think?

Ian.

#3 lore raw
Quoted 30 lines · George Dunlap
Quoted 29 lines · Ian Campbell
Quoted 28 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Wilk <[email protected]>

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2:
- Restructure functions to make sure init and dispose are properly called.

Quoted 8 lines
Quoted 4 lines

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Specifically the "hacky short-term fix" is <[email protected]> ?

I could live with that, perhaps with the commit log explaining that a little.

Konrad?

Quoted 64 lines

Or, if the valgrind thing is really important, I could use the change you suggested, and do "return rc ? 1 : 0;" but I really think that's going in the wrong direction...

-George

Quoted 56 lines
Quoted 11 lines
---
  tools/libxl/libxl.c      |  2 --
  tools/libxl/xl_cmdimpl.c | 28 +++++++++++++++++++++-------
  2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +0 -0
index f7961f6..d9c4ce7 100644

tools/libxl/libxl.c int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, · line 2614

Quoted 4 lines
tools/libxl/libxl.c +0 -1
@@ -2611,8 +2611,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
      if (devid < 0)
          return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);

_init functions are idempotent, so this is harmless, I think. Existing callers (including things which aren't xl) might be relying on it. Outside of a freeze period that might be acceptable (those callers are buggy) but since you are asking for a freeze exception I think this may be going a step too far in cleaning things up.

In terms of other callers you've missed tools/ocaml/libs/xl/xenlight_stubs.c (which appears buggy to me) in tree, plus whatever use e.g. libvirt makes of it.

tools/libxl/xl_cmdimpl.c static void parse_disk_config_multistring(XLU_Config **config, · line 488

Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0 -1
index 3c9f146..25af715 100644
@@ -485,8 +485,6 @@ static void parse_disk_config_multistring(XLU_Config **config,
  {
      int e;
 
-    libxl_device_disk_init(disk);

Likewise here, although to a lesser extent since this is xl not libxl.

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6381

Quoted 6 lines
tools/libxl/xl_cmdimpl.c +0 -1
@@ -6378,13 +6382,17 @@ int main_blockattach(int argc, char **argv)
          printf("disk: %s\n", json);
          free(json);
          if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-        return 0;

You should set rc = 0 here rather than initing it at declaration to catch error paths which don't set the result. (we aren't very consistent about this in the code today so I'm only mentioning it because other changes seem to be needed, if that turns out not to be the case and there's no need for v3 then this shouldn't block acceptance)

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6385

Quoted 1 line
tools/libxl/xl_cmdimpl.c +1 -0
+        goto out;

I'm not 100% convinced by the use of the goto out error handling style for a success path, but it's probably better than duplicating the exit path or adding !dryrun checks to all the following operations. Ian, since you recently posted updated coding style for things around this, what do you think?

Ian.

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Quoted 34 lines · Ian Campbell
Quoted 33 lines · George Dunlap
Quoted 31 lines · Ian Campbell
Quoted 21 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

--- CC: Ian Campbell <[email protected]> CC: Ian Jackson <[email protected]> CC: Wei Liu <[email protected]> CC: Konrad Wilk <[email protected]>

Quoted 5 lines

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2: - Restructure functions to make sure init and dispose are properly called.

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Quoted 6 lines
Quoted 3 lines

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Specifically the "hacky short-term fix" is <[email protected]> ?

Yes -- the one you found somewhat wanting. :-)

Quoted 2 lines

I could live with that, perhaps with the commit log explaining that a little.

Do you want to add that, or shall I add it and re-submit?

-George

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBCgAGBQJUbg4KAAoJELIVx6fHhBvtXvQH/1Lg2NPR1bPElcjninQ8Qv51 deoj9lZKeMvRECSM58CTrQHo83+9jqhb9URXDRMxJ2DQqK0UTTqzNkpiolwojLq4 PkGNy5Pwlfp35meYaVdADjnwatb05+ZM/kCGVlfF70aok3Das6BdXL82MT0Btfvj Z+0GBxNgmmkV+WdOvuKzQx0Zyq6vWpRXPz4EjyU5ypm4DSkPw+xbH65Ja/d+uxhD il06GKvxxnbAFa7zvdGavwkxpPJmp8s4XAheqwRTRtTZMubiHUm/Ycul/774P81i 4/A94owTU1BN10FWa1aSqszHY+M2rKZXAgxUrqNPzyPSRbYn4+mASORB1+WEpDo= =1dUr
-----END PGP SIGNATURE-----

#5 lore raw
Quoted 42 lines · George Dunlap
Quoted 34 lines · Ian Campbell
Quoted 33 lines · George Dunlap
Quoted 31 lines · Ian Campbell
Quoted 21 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

--- CC: Ian Campbell <[email protected]> CC: Ian Jackson <[email protected]> CC: Wei Liu <[email protected]> CC: Konrad Wilk <[email protected]>

Quoted 5 lines

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2: - Restructure functions to make sure init and dispose are properly called.

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Quoted 6 lines
Quoted 3 lines

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Specifically the "hacky short-term fix" is <[email protected]> ?

Quoted 6 lines

Yes -- the one you found somewhat wanting. :-)

Quoted 2 lines

I could live with that, perhaps with the commit log explaining that a little.

Do you want to add that, or shall I add it and re-submit?

If you provide the text I'll just fold it in, unless having written it you find invoking send-email to be so trivial it's actually easier.

Ian.

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Quoted 50 lines · Ian Campbell
Quoted 49 lines · George Dunlap
Quoted 38 lines · Ian Campbell
Quoted 37 lines · George Dunlap
Quoted 35 lines · Ian Campbell
Quoted 24 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

Signed-off-by: George Dunlap <[email protected]> --- CC: Ian Campbell <[email protected]> CC: Ian Jackson <[email protected]> CC: Wei Liu <[email protected]> CC: Konrad Wilk <[email protected]>

Quoted 5 lines

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2: - Restructure functions to make sure init and dispose are properly called.

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Quoted 7 lines
Quoted 3 lines

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Specifically the "hacky short-term fix" is <[email protected]> ?

Yes -- the one you found somewhat wanting. :-)

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I could live with that, perhaps with the commit log explaining that a little.

Do you want to add that, or shall I add it and re-submit?

If you provide the text I'll just fold it in, unless having written it you find invoking send-email to be so trivial it's actually easier.

Unfortunately I think I clobbered v1 in my git tree while developing v2. It probably hasn't been garbage collected yet, but I'll just reply to v1 with an updated changelog.

-George

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBCgAGBQJUbg/SAAoJELIVx6fHhBvt7CUIAI75XUObbYy0/Zkinx2eVcLE d+fXSkVFWtwPPI2bfw3DyLtbMzAGxeNLhwwuLZ47b1ROam7fDcMzRp9t36NpetkY E+NoBk7chO8sD8lveGukipNiX0qTSKVQAc721CHwgO3L3yIw7t4iSsylR0Ntzew1 twiL68v1vwC/N70PJYSzW0v1dFQODX7YV5RreFZ+Hon6og8dNvKmlRojPC77Qid0 kAEiL2JouKrQ48ONr1cKKPWHJqNFL3+pZHbZCi9d+OF0pmOhlaVXZFccLlr26xq+ SMQx0rLyTQF6rJRUaQ0zVgMK82BxjVWXO5rIPQggnwwY0ILaYY9YmmPWw86kD0M= =04qs
-----END PGP SIGNATURE-----

#7 lore raw
In reply to Ian Campbell
Quoted 40 lines · Ian Campbell
Quoted 30 lines · George Dunlap
Quoted 29 lines · Ian Campbell
Quoted 28 lines · George Dunlap

Return proper error codes on failure so that scripts can tell whether the command completed properly or not.

Also while we're at it, normalize init and dispose of libxl_device_disk structures. This means calling init and dispose in the actual functions where they are declared.

This in turn means changing parse_disk_config_multistring() to not call libxl_device_disk_init. And that in turn means changes to callers of parse_disk_config().

It also means removing libxl_device_disk_init() from libxl.c:libxl_vdev_to_device_disk(). This is only called from xl_cmdimpl.c.

---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Konrad Wilk <[email protected]>

Release justification: This is a bug fix. It's a fairly minor one, but it's also a very simple one.

v2:
- Restructure functions to make sure init and dispose are properly called.

Quoted 8 lines
Quoted 4 lines

Sadly this bit has somewhat reduced the truth of the second half of your release justification, since the patch is a fair bit more subtle though. Although IMHO it hasn't invalidated the case for taking the patch for 4.5 (modulo comments below).

Well, I think we can take the hacky short-term fix I posted before, which is simple, and do a proper fix after the 4.6 dev window opens up; or we can do a more complete fix now.

Quoted 7 lines

Specifically the "hacky short-term fix" is <[email protected]> ?

I could live with that, perhaps with the commit log explaining that a little.

Konrad?

<hands George the band-aid tape>

Quoted 67 lines
Quoted 65 lines

Or, if the valgrind thing is really important, I could use the change you suggested, and do "return rc ? 1 : 0;" but I really think that's going in the wrong direction...

-George

Quoted 56 lines
Quoted 11 lines
---
  tools/libxl/libxl.c      |  2 --
  tools/libxl/xl_cmdimpl.c | 28 +++++++++++++++++++++-------
  2 files changed, 21 insertions(+), 9 deletions(-)
tools/libxl/libxl.c +0 -0
index f7961f6..d9c4ce7 100644

tools/libxl/libxl.c int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, · line 2614

Quoted 4 lines
tools/libxl/libxl.c +0 -1
@@ -2611,8 +2611,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid,
      if (devid < 0)
          return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);

_init functions are idempotent, so this is harmless, I think. Existing callers (including things which aren't xl) might be relying on it. Outside of a freeze period that might be acceptable (those callers are buggy) but since you are asking for a freeze exception I think this may be going a step too far in cleaning things up.

In terms of other callers you've missed tools/ocaml/libs/xl/xenlight_stubs.c (which appears buggy to me) in tree, plus whatever use e.g. libvirt makes of it.

tools/libxl/xl_cmdimpl.c static void parse_disk_config_multistring(XLU_Config **config, · line 488

Quoted 9 lines
tools/libxl/xl_cmdimpl.c +0 -1
index 3c9f146..25af715 100644
@@ -485,8 +485,6 @@ static void parse_disk_config_multistring(XLU_Config **config,
  {
      int e;
 
-    libxl_device_disk_init(disk);

Likewise here, although to a lesser extent since this is xl not libxl.

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6381

Quoted 6 lines
tools/libxl/xl_cmdimpl.c +0 -1
@@ -6378,13 +6382,17 @@ int main_blockattach(int argc, char **argv)
          printf("disk: %s\n", json);
          free(json);
          if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-        return 0;

You should set rc = 0 here rather than initing it at declaration to catch error paths which don't set the result. (we aren't very consistent about this in the code today so I'm only mentioning it because other changes seem to be needed, if that turns out not to be the case and there's no need for v3 then this shouldn't block acceptance)

tools/libxl/xl_cmdimpl.c int main_blockattach(int argc, char **argv) · line 6385

Quoted 1 line
tools/libxl/xl_cmdimpl.c +1 -0
+        goto out;

I'm not 100% convinced by the use of the goto out error handling style for a success path, but it's probably better than duplicating the exit path or adding !dryrun checks to all the following operations. Ian, since you recently posted updated coding style for things around this, what do you think?

Ian.