Skip to content

Commit 495d357

Browse files
committed
md/linear: use call_rcu to free obsolete 'conf' structures.
Current, when we update the 'conf' structure, when adding a drive to a linear array, we keep the old version around until the array is finally stopped, as it is not safe to free it immediately. Now that we have rcu protection on all accesses to 'conf', we can use call_rcu to free it more promptly. Signed-off-by: NeilBrown <neilb@suse.de>
1 parent af11c39 commit 495d357

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎drivers/md/linear.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ static int linear_run (mddev_t *mddev)
223223
return 0;
224224
}
225225

226+
static void free_conf(struct rcu_head *head)
227+
{
228+
linear_conf_t *conf = container_of(head, linear_conf_t, rcu);
229+
kfree(conf);
230+
}
231+
226232
static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
227233
{
228234
/* Adding a drive to a linear array allows the array to grow.
@@ -233,7 +239,7 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
233239
* The current one is never freed until the array is stopped.
234240
* This avoids races.
235241
*/
236-
linear_conf_t *newconf;
242+
linear_conf_t *newconf, *oldconf;
237243

238244
if (rdev->saved_raid_disk != mddev->raid_disks)
239245
return -EINVAL;
@@ -245,11 +251,12 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
245251
if (!newconf)
246252
return -ENOMEM;
247253

248-
newconf->prev = mddev->private;
254+
oldconf = rcu_dereference(mddev->private);
249255
mddev->raid_disks++;
250256
rcu_assign_pointer(mddev->private, newconf);
251257
md_set_array_sectors(mddev, linear_size(mddev, 0, 0));
252258
set_capacity(mddev->gendisk, mddev->array_sectors);
259+
call_rcu(&oldconf->rcu, free_conf);
253260
return 0;
254261
}
255262

@@ -261,14 +268,12 @@ static int linear_stop (mddev_t *mddev)
261268
* We do not require rcu protection here since
262269
* we hold reconfig_mutex for both linear_add and
263270
* linear_stop, so they cannot race.
271+
* We should make sure any old 'conf's are properly
272+
* freed though.
264273
*/
265-
274+
rcu_barrier();
266275
blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/
267-
do {
268-
linear_conf_t *t = conf->prev;
269-
kfree(conf);
270-
conf = t;
271-
} while (conf);
276+
kfree(conf);
272277

273278
return 0;
274279
}

‎drivers/md/linear.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ typedef struct dev_info dev_info_t;
1010

1111
struct linear_private_data
1212
{
13-
struct linear_private_data *prev; /* earlier version */
1413
sector_t array_sectors;
1514
dev_info_t disks[0];
15+
struct rcu_head rcu;
1616
};
1717

1818

0 commit comments

Comments
 (0)