mdadm-3.3.1-mdmon-allow-prepare_update-to-report-failure.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From 5fe6f031d9a21a935f0ef1b1fbdb314b53f2199f Mon Sep 17 00:00:00 2001
  2. From: NeilBrown <neilb@suse.de>
  3. Date: Thu, 10 Jul 2014 15:54:02 +1000
  4. Subject: [PATCH 11/14] mdmon: allow prepare_update to report failure.
  5. If 'prepare_update' fails for some reason there is little
  6. point continuing on to 'process_update'.
  7. For now only malloc failures are caught, but other failures
  8. will be considered in future.
  9. Signed-off-by: NeilBrown <neilb@suse.de>
  10. ---
  11. managemon.c | 3 ++-
  12. mdadm.h | 5 ++++-
  13. super-ddf.c | 8 +++++---
  14. super-intel.c | 9 +++++----
  15. 4 files changed, 16 insertions(+), 9 deletions(-)
  16. diff --git a/managemon.c b/managemon.c
  17. index 5f7e2ce..1c9eccc 100644
  18. --- a/managemon.c
  19. +++ b/managemon.c
  20. @@ -819,7 +819,8 @@ static void handle_message(struct supertype *container, struct metadata_update *
  21. mu->space_list = NULL;
  22. mu->next = NULL;
  23. if (container->ss->prepare_update)
  24. - container->ss->prepare_update(container, mu);
  25. + if (!container->ss->prepare_update(container, mu))
  26. + free_updates(&mu);
  27. queue_metadata_update(mu);
  28. }
  29. }
  30. diff --git a/mdadm.h b/mdadm.h
  31. index 914d67c..02a9288 100644
  32. --- a/mdadm.h
  33. +++ b/mdadm.h
  34. @@ -929,7 +929,10 @@ extern struct superswitch {
  35. void (*sync_metadata)(struct supertype *st);
  36. void (*process_update)(struct supertype *st,
  37. struct metadata_update *update);
  38. - void (*prepare_update)(struct supertype *st,
  39. + /* Prepare updates allocates extra memory that might be
  40. + * needed. If the update cannot be understood, return 0.
  41. + */
  42. + int (*prepare_update)(struct supertype *st,
  43. struct metadata_update *update);
  44. /* activate_spare will check if the array is degraded and, if it
  45. diff --git a/super-ddf.c b/super-ddf.c
  46. index ab9fc46..1e43ca2 100644
  47. --- a/super-ddf.c
  48. +++ b/super-ddf.c
  49. @@ -4906,8 +4906,8 @@ static void ddf_process_update(struct supertype *st,
  50. /* case DDF_SPARE_ASSIGN_MAGIC */
  51. }
  52. -static void ddf_prepare_update(struct supertype *st,
  53. - struct metadata_update *update)
  54. +static int ddf_prepare_update(struct supertype *st,
  55. + struct metadata_update *update)
  56. {
  57. /* This update arrived at managemon.
  58. * We are about to pass it to monitor.
  59. @@ -4922,15 +4922,17 @@ static void ddf_prepare_update(struct supertype *st,
  60. offsetof(struct vcl, conf)
  61. + ddf->conf_rec_len * 512) != 0) {
  62. update->space = NULL;
  63. - return;
  64. + return 0;
  65. }
  66. vcl = update->space;
  67. vcl->conf.sec_elmnt_count = conf->sec_elmnt_count;
  68. if (alloc_other_bvds(ddf, vcl) != 0) {
  69. free(update->space);
  70. update->space = NULL;
  71. + return 0;
  72. }
  73. }
  74. + return 1;
  75. }
  76. /*
  77. diff --git a/super-intel.c b/super-intel.c
  78. index 7734bde..2547b4a 100644
  79. --- a/super-intel.c
  80. +++ b/super-intel.c
  81. @@ -8607,8 +8607,8 @@ static void imsm_process_update(struct supertype *st,
  82. static struct mdinfo *get_spares_for_grow(struct supertype *st);
  83. -static void imsm_prepare_update(struct supertype *st,
  84. - struct metadata_update *update)
  85. +static int imsm_prepare_update(struct supertype *st,
  86. + struct metadata_update *update)
  87. {
  88. /**
  89. * Allocate space to hold new disk entries, raid-device entries or a new
  90. @@ -8828,6 +8828,7 @@ static void imsm_prepare_update(struct supertype *st,
  91. else
  92. super->next_buf = NULL;
  93. }
  94. + return 1;
  95. }
  96. /* must be called while manager is quiesced */
  97. @@ -9716,8 +9717,8 @@ static void imsm_update_metadata_locally(struct supertype *st,
  98. mu.space = NULL;
  99. mu.space_list = NULL;
  100. mu.next = NULL;
  101. - imsm_prepare_update(st, &mu);
  102. - imsm_process_update(st, &mu);
  103. + if (imsm_prepare_update(st, &mu))
  104. + imsm_process_update(st, &mu);
  105. while (mu.space_list) {
  106. void **space = mu.space_list;
  107. --
  108. 2.0.0