Skip to contentSkip to conversation

md: raid10: remove VLAIS

PATCH In review Matthias Kaehlcke 4 participants 7 messages Oct 5, 2017 – Oct 6, 2017 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: raid10: remove VLAIS

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +8 -5
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;
-		struct r10dev devs[conf->copies];
-	} on_stack;
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
+	if (!r10b)
+		return -ENOMEM;
+
 	/* reshape IOs share pages from .devs[0].bio */
 	pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
 			/* couldn't read this block, must give up */
 			set_bit(MD_RECOVERY_INTR,
 				&mddev->recovery);
+			kfree(r10b);
 			return -EIO;
 		}
 		sectors -= s;
 		idx++;
 	}
+	kfree(r10b);
 	return 0;
 }
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Matthias Kaehlcke

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

Quoted 47 lines
---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +8 -6
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
        /* Use sync reads to get the blocks from somewhere else */
        int sectors = r10_bio->sectors;
        struct r10conf *conf = mddev->private;
-       struct {
-               struct r10bio r10_bio;
-               struct r10dev devs[conf->copies];
-       } on_stack;
-       struct r10bio *r10b = &on_stack.r10_bio;
+       struct r10bio *r10b;
        int slot = 0;
        int idx = 0;
        struct page **pages;
 
+       r10b = kmalloc(sizeof(*r10b) +
+              sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
+       if (!r10b)
+               return -ENOMEM;
+
        /* reshape IOs share pages from .devs[0].bio */
        pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
                        /* couldn't read this block, must give up */
                        set_bit(MD_RECOVERY_INTR,
                                &mddev->recovery);
+                       kfree(r10b);
                        return -EIO;
                }
                sectors -= s;
                idx++;
        }
+       kfree(r10b);
        return 0;
 }
 
--

2.14.2.920.gcf0c67979c-goog

#2 lore raw
In reply to Matthias Kaehlcke
Quoted 26 lines · Matthias Kaehlcke

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +0 -4
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;
-		struct r10dev devs[conf->copies];
-	} on_stack;

drivers/md/raid10.c static int handle_reshape_read_error(struct mddev *mddev, · line 4589

Quoted 10 lines
drivers/md/raid10.c +5 -1
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);
+	if (!r10b)
+		return -ENOMEM;

I'll apply this patch with 'set_bit(MD_RECOVERY_INTR, &mddev->recovery);' added here, thanks!

Quoted 21 lines
drivers/md/raid10.c +3 -0
+
 	/* reshape IOs share pages from .devs[0].bio */
 	pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
 			/* couldn't read this block, must give up */
 			set_bit(MD_RECOVERY_INTR,
 				&mddev->recovery);
+			kfree(r10b);
 			return -EIO;
 		}
 		sectors -= s;
 		idx++;
 	}
+	kfree(r10b);
 	return 0;
 }
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
#3 lore raw
In reply to Matthias Kaehlcke
Quoted 24 lines · Matthias Kaehlcke

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +0 -2
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;

drivers/md/raid10.c static int handle_reshape_read_error(struct mddev *mddev, · line 4587

Quoted 10 lines
drivers/md/raid10.c +3 -3
-		struct r10dev devs[conf->copies];
-	} on_stack;
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);

GFP_KERNEL isn't a good idea here.
This could wait for writeback, and if writeback tries to write to the region of the array which is being reshaped, it might deadlock.

GFP_NOIO is safer.

given that conf->copies is almost always 2 it might be nicer to have

	struct {
		struct r10bio r10_bio;
		struct r10dev devs[2];
	} on_stack;

        struct r10bio *r10b;

	if (conf->copies <= ARRAY_SIZE(on_stack.devs))
        	r10b = &on_stack.r10_bio;
        else
        	r10b = kmalloc(sizeof(*r10b) +
			       sizeof(struct r10dev) * conf->copies, GFP_NOIO);

Thanks,
NeilBrown

Quoted 22 lines
drivers/md/raid10.c +5 -0
+	if (!r10b)
+		return -ENOMEM;
+
 	/* reshape IOs share pages from .devs[0].bio */
 	pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
 			/* couldn't read this block, must give up */
 			set_bit(MD_RECOVERY_INTR,
 				&mddev->recovery);
+			kfree(r10b);
 			return -EIO;
 		}
 		sectors -= s;
 		idx++;
 	}
+	kfree(r10b);
 	return 0;
 }
 
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
#4 lore raw

Hi Neil,

El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:

Quoted 34 lines · Matthias Kaehlcke
Quoted 33 lines

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +1 -5
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;
-		struct r10dev devs[conf->copies];
-	} on_stack;
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
Quoted 8 lines

drivers/md/raid10.c static int handle_reshape_read_error(struct mddev *mddev, · line 4587

Quoted 2 lines
drivers/md/raid10.c +2 -0
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);

GFP_KERNEL isn't a good idea here.
This could wait for writeback, and if writeback tries to write to the region of the array which is being reshaped, it might deadlock.

GFP_NOIO is safer.

Good point, thanks!

Quoted 15 lines

given that conf->copies is almost always 2 it might be nicer to have

	struct {
		struct r10bio r10_bio;
		struct r10dev devs[2];
	} on_stack;

        struct r10bio *r10b;

	if (conf->copies <= ARRAY_SIZE(on_stack.devs))
        	r10b = &on_stack.r10_bio;
        else
        	r10b = kmalloc(sizeof(*r10b) +
			       sizeof(struct r10dev) * conf->copies, GFP_NOIO);

It would add also add an extra condition to determine if r10b needs to be freed or not.

Given that array reshaping is a rare operation and an error during this operation is an exceptional condition I think the simpler code with always dynamic allocation is preferable. That said I'm fine with reworking the patch according to your suggestion if you or Shaohua prefer it.

Matthias

Quoted 20 lines
Quoted 20 lines
drivers/md/raid10.c +5 -0
+	if (!r10b)
+		return -ENOMEM;
+
 	/* reshape IOs share pages from .devs[0].bio */
 	pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
 			/* couldn't read this block, must give up */
 			set_bit(MD_RECOVERY_INTR,
 				&mddev->recovery);
+			kfree(r10b);
 			return -EIO;
 		}
 		sectors -= s;
 		idx++;
 	}
+	kfree(r10b);
 	return 0;
 }
 
#5 lore raw
Quoted 59 lines · Matthias Kaehlcke

Hi Neil,

El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:

Quoted 34 lines · Matthias Kaehlcke
Quoted 33 lines

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +1 -5
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;
-		struct r10dev devs[conf->copies];
-	} on_stack;
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
Quoted 8 lines

drivers/md/raid10.c static int handle_reshape_read_error(struct mddev *mddev, · line 4587

Quoted 2 lines
drivers/md/raid10.c +2 -0
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);

GFP_KERNEL isn't a good idea here.
This could wait for writeback, and if writeback tries to write to the region of the array which is being reshaped, it might deadlock.

GFP_NOIO is safer.

Good point, thanks!

Quoted 10 lines

given that conf->copies is almost always 2 it might be nicer to have

	struct {
		struct r10bio r10_bio;
		struct r10dev devs[2];
	} on_stack;

        struct r10bio *r10b;
Quoted 8 lines
Quoted 5 lines
	if (conf->copies <= ARRAY_SIZE(on_stack.devs))
        	r10b = &on_stack.r10_bio;
        else
        	r10b = kmalloc(sizeof(*r10b) +
			       sizeof(struct r10dev) * conf->copies, GFP_NOIO);

It would add also add an extra condition to determine if r10b needs to be freed or not.

True.

Quoted 6 lines

Given that array reshaping is a rare operation and an error during this operation is an exceptional condition I think the simpler code with always dynamic allocation is preferable. That said I'm fine with reworking the patch according to your suggestion if you or Shaohua prefer it.

I don't feel strongly about it. As long as the GFP_KERNEL->GFP_NOIO change happens I'm OK with this patch.

Thanks,
NeilBrown

Quoted 23 lines

Matthias

Quoted 20 lines
Quoted 20 lines
drivers/md/raid10.c +5 -0
+	if (!r10b)
+		return -ENOMEM;
+
 	/* reshape IOs share pages from .devs[0].bio */
 	pages = get_resync_pages(r10_bio->devs[0].bio)->pages;
 
@@ -4635,11 +4636,13 @@ static int handle_reshape_read_error(struct mddev *mddev,
 			/* couldn't read this block, must give up */
 			set_bit(MD_RECOVERY_INTR,
 				&mddev->recovery);
+			kfree(r10b);
 			return -EIO;
 		}
 		sectors -= s;
 		idx++;
 	}
+	kfree(r10b);
 	return 0;
 }
 
#6 lore raw
Quoted 73 lines · Neil Brown
Quoted 59 lines · Matthias Kaehlcke

Hi Neil,

El Fri, Oct 06, 2017 at 10:58:59AM +1100 NeilBrown ha dit:

Quoted 34 lines · Matthias Kaehlcke
Quoted 33 lines

The raid10 driver can't be built with clang since it uses a variable length array in a structure (VLAIS):

drivers/md/raid10.c:4583:17: error: fields must have a constant size:
'variable length array in structure' extension will never be supported

Allocate the r10bio struct with kmalloc instead of using the VLAIS construct.

---
 drivers/md/raid10.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/md/raid10.c +1 -5
index 374df5796649..9616163eaf8c 100644
@@ -4578,15 +4578,16 @@ static int handle_reshape_read_error(struct mddev *mddev,
 	/* Use sync reads to get the blocks from somewhere else */
 	int sectors = r10_bio->sectors;
 	struct r10conf *conf = mddev->private;
-	struct {
-		struct r10bio r10_bio;
-		struct r10dev devs[conf->copies];
-	} on_stack;
-	struct r10bio *r10b = &on_stack.r10_bio;
+	struct r10bio *r10b;
 	int slot = 0;
 	int idx = 0;
 	struct page **pages;
 
Quoted 8 lines

drivers/md/raid10.c static int handle_reshape_read_error(struct mddev *mddev, · line 4587

Quoted 2 lines
drivers/md/raid10.c +2 -0
+	r10b = kmalloc(sizeof(*r10b) +
+	       sizeof(struct r10dev) * conf->copies, GFP_KERNEL);

GFP_KERNEL isn't a good idea here.
This could wait for writeback, and if writeback tries to write to the region of the array which is being reshaped, it might deadlock.

GFP_NOIO is safer.

Good point, thanks!

Quoted 10 lines

given that conf->copies is almost always 2 it might be nicer to have

	struct {
		struct r10bio r10_bio;
		struct r10dev devs[2];
	} on_stack;

        struct r10bio *r10b;
Quoted 8 lines
Quoted 5 lines
	if (conf->copies <= ARRAY_SIZE(on_stack.devs))
        	r10b = &on_stack.r10_bio;
        else
        	r10b = kmalloc(sizeof(*r10b) +
			       sizeof(struct r10dev) * conf->copies, GFP_NOIO);

It would add also add an extra condition to determine if r10b needs to be freed or not.

True.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

Given that array reshaping is a rare operation and an error during this operation is an exceptional condition I think the simpler code with always dynamic allocation is preferable. That said I'm fine with reworking the patch according to your suggestion if you or Shaohua prefer it.

I don't feel strongly about it. As long as the GFP_KERNEL->GFP_NOIO change happens I'm OK with this patch.

Let's use GFP_NOIO then, should not be big deal. I updated the patch.

Thanks,
Shaohua