Skip to contentSkip to conversation

Introduction

PATCH In review NeilBrown 3 participants 8 messages Oct 31, 2005 MD RAID

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 Introduction

Two patches for md in 2.6.14-rc5-mm1 (First one depends on -mm stuff, second should apply to most recent 2.6 kernels).

I'd like to review the sysfs a bit more before it goes to Linus, but the rest can go anytime.
Thanks,
NeilBrown

[PATCH md 001 of 2] Remove attempt to use dynamic names in sysfs for component devices on an MD array. [PATCH md 002 of 2] Allow md arrays to be started read-only (module parameter).

author
#1 lore raw

PATCH 1/1 Remove attempt to use dynamic names in sysfs for component devices on an MD array.

With version-0.90 superblock, component devices on an md device to not have any stable name related to the array -(version-1 assigns a fixed index when a device is added to an array, and this remains despit any hot-swap).

The intial code for making these devices appear in sysfs used dynamic names, which would change whenever a hot-spare was swapped for a failed or missing device.
This turns out not to be practical in sysfs for a number of reasons.

This patch changes then naming of component devices to be based on the result of 'bdevname'. This is stable and should be unique.

### Diffstat output

 ./drivers/md/md.c |   40 ++++++----------------------------------
 1 file changed, 6 insertions(+), 34 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +6 -34
diff ./drivers/md/md.c~current~ ./drivers/md/md.c
@@ -762,7 +762,7 @@ static void super_90_sync(mddev_t *mddev
 	struct list_head *tmp;
 	mdk_rdev_t *rdev2;
 	int next_spare = mddev->raid_disks;
-	char nm[20];
+
 
 	/* make rdev->sb match mddev data..
 	 *
@@ -776,7 +776,6 @@ static void super_90_sync(mddev_t *mddev
 	 */
 	int i;
 	int active=0, working=0,failed=0,spare=0,nr_disks=0;
-	unsigned int fixdesc=0;
 
 	rdev->sb_size = MD_SB_BYTES;
 
@@ -830,16 +829,7 @@ static void super_90_sync(mddev_t *mddev
 			desc_nr = rdev2->raid_disk;
 		else
 			desc_nr = next_spare++;
-		if (desc_nr != rdev2->desc_nr) {
-			fixdesc |= (1 << desc_nr);
-			rdev2->desc_nr = desc_nr;
-			if (rdev2->raid_disk >= 0) {
-				sprintf(nm, "rd%d", rdev2->raid_disk);
-				sysfs_remove_link(&mddev->kobj, nm);
-			}
-			sysfs_remove_link(&rdev2->kobj, "block");
-			kobject_del(&rdev2->kobj);
-		}
+		rdev2->desc_nr = desc_nr;
 		d = &sb->disks[rdev2->desc_nr];
 		nr_disks++;
 		d->number = rdev2->desc_nr;
@@ -866,25 +856,6 @@ static void super_90_sync(mddev_t *mddev
 		if (test_bit(WriteMostly, &rdev2->flags))
 			d->state |= (1<<MD_DISK_WRITEMOSTLY);
 	}
-	if (fixdesc)
-		ITERATE_RDEV(mddev,rdev2,tmp)
-			if (fixdesc & (1<<rdev2->desc_nr)) {
-				snprintf(rdev2->kobj.name, KOBJ_NAME_LEN, "dev%d",
-					 rdev2->desc_nr);
-				/* kobject_add gets a ref on the parent, so
-				 * we have to drop the one we already have
-				 */
-				kobject_add(&rdev2->kobj);
-				kobject_put(rdev->kobj.parent);
-				sysfs_create_link(&rdev2->kobj,
-						  &rdev2->bdev->bd_disk->kobj,
-						  "block");
-				if (rdev2->raid_disk >= 0) {
-					sprintf(nm, "rd%d", rdev2->raid_disk);
-					sysfs_create_link(&mddev->kobj,
-							  &rdev2->kobj, nm);
-				}
-			}
 	/* now set the "removed" and "faulty" bits on any missing devices */
 	for (i=0 ; i < mddev->raid_disks ; i++) {
 		mdp_disk_t *d = &sb->disks[i];
@@ -1237,13 +1208,14 @@ static int bind_rdev_to_array(mdk_rdev_t
 		if (find_rdev_nr(mddev, rdev->desc_nr))
 			return -EBUSY;
 	}
+	bdevname(rdev->bdev,b);
+	if (kobject_set_name(&rdev->kobj, "dev-%s", b) < 0)
+		return -ENOMEM;
 			
 	list_add(&rdev->same_set, &mddev->disks);
 	rdev->mddev = mddev;
-	printk(KERN_INFO "md: bind<%s>\n", bdevname(rdev->bdev,b));
+	printk(KERN_INFO "md: bind<%s>\n", b);
 
-	rdev->kobj.k_name = NULL;
-	snprintf(rdev->kobj.name, KOBJ_NAME_LEN, "dev%d", rdev->desc_nr);
 	rdev->kobj.parent = &mddev->kobj;
 	kobject_add(&rdev->kobj);
 
author
#2 lore raw

PATCH 1/1 Allow md arrays to be started read-only (module parameter).

In reply to NeilBrown

When an md array is started, the superblock will be written, and resync may commense. This is not good if you want to be completely read-only as, for example, when preparing to resume from a suspend-to-disk image.

So introduce a module parameter "start_ro" which can be set to '1' at boot, at module load, or via
/sys/module/md_mod/parameters/start_ro

When this is set, new arrays get an 'auto-ro' mode, which disables all internal io (superblock updates, resync, recovery) and is automatically switched to 'rw' when the first write request arrives.

The array can be set to true 'ro' mode using 'mdadm -r' before the first write request, or resync can be started without a write using 'mdadm -w'.

### Diffstat output

 ./drivers/md/md.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 8 deletions(-)
drivers/md/md.c renamed from drivers/md/md.c~current~ +51 -8
diff ./drivers/md/md.c~current~ ./drivers/md/md.c
@@ -131,6 +131,8 @@ static ctl_table raid_root_table[] = {
 
 static struct block_device_operations md_fops;
 
+static int start_readonly;
+
 /*
  * Enables to iterate over all existing md arrays
  * all_mddevs_lock protects this list.
@@ -2029,6 +2031,9 @@ static int do_md_run(mddev_t * mddev)
 	mddev->resync_max_sectors = mddev->size << 1; /* may be over-ridden by personality */
 	mddev->barriers_work = 1;
 
+	if (start_readonly)
+		mddev->ro = 2; /* read-only, but switch on first write */
+
 	/* before we start the array running, initialise the bitmap */
 	err = bitmap_create(mddev);
 	if (err)
@@ -2141,7 +2146,7 @@ static int do_md_stop(mddev_t * mddev, i
 
 		if (ro) {
 			err  = -ENXIO;
-			if (mddev->ro)
+			if (mddev->ro==1)
 				goto out;
 			mddev->ro = 1;
 		} else {
@@ -3258,12 +3263,22 @@ static int md_ioctl(struct inode *inode,
 
 	/*
 	 * The remaining ioctls are changing the state of the
-	 * superblock, so we do not allow read-only arrays
-	 * here:
+	 * superblock, so we do not allow them on read-only arrays.
+	 * However non-MD ioctls (e.g. get-size) will still come through
+	 * here and hit the 'default' below, so only disallow
+	 * 'md' ioctls, and switch to rw mode if started auto-readonly.
 	 */
-	if (mddev->ro) {
-		err = -EROFS;
-		goto abort_unlock;
+	if (_IOC_TYPE(cmd) == MD_MAJOR &&
+	    mddev->ro && mddev->pers) {
+		if (mddev->ro == 2) {
+			mddev->ro = 0;
+		set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+		md_wakeup_thread(mddev->thread);
+
+		} else {
+			err = -EROFS;
+			goto abort_unlock;
+		}
 	}
 
 	switch (cmd)
@@ -3651,8 +3666,10 @@ static int md_seq_show(struct seq_file *
 		seq_printf(seq, "%s : %sactive", mdname(mddev),
 						mddev->pers ? "" : "in");
 		if (mddev->pers) {
-			if (mddev->ro)
+			if (mddev->ro==1)
 				seq_printf(seq, " (read-only)");
+			if (mddev->ro==2)
+				seq_printf(seq, "(auto-read-only)");
 			seq_printf(seq, " %s", mddev->pers->name);
 		}
 
@@ -3696,7 +3713,9 @@ static int md_seq_show(struct seq_file *
 				status_resync (seq, mddev);
 				seq_printf(seq, "\n      ");
 			} else if (mddev->curr_resync == 1 || mddev->curr_resync == 2)
-				seq_printf(seq, "	resync=DELAYED\n      ");
+				seq_printf(seq, "\tresync=DELAYED\n      ");
+			else if (mddev->recovery_cp < MaxSector)
+				seq_printf(seq, "\tresync=PENDING\n      ");
 		} else
 			seq_printf(seq, "\n       ");
 
@@ -3833,6 +3852,13 @@ void md_write_start(mddev_t *mddev, stru
 	if (bio_data_dir(bi) != WRITE)
 		return;
 
+	BUG_ON(mddev->ro == 1);
+	if (mddev->ro == 2) {
+		/* need to switch to read/write */
+		mddev->ro = 0;
+		set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
+		md_wakeup_thread(mddev->thread);
+	}
 	atomic_inc(&mddev->writes_pending);
 	if (mddev->in_sync) {
 		spin_lock_irq(&mddev->write_lock);
@@ -4429,6 +4455,23 @@ static __exit void md_exit(void)
 module_init(md_init)
 module_exit(md_exit)
 
+static int get_ro(char *buffer, struct kernel_param *kp)
+{
+	return sprintf(buffer, "%d", start_readonly);
+}
+static int set_ro(const char *val, struct kernel_param *kp)
+{
+	char *e;
+	int num = simple_strtoul(val, &e, 10);
+	if (*val && (*e == '\0' || *e == '\n')) {
+		start_readonly = num;
+		return 0;;
+	}
+	return -EINVAL;
+}
+
+module_param_call(start_ro, set_ro, get_ro, NULL, 0600);
+
 EXPORT_SYMBOL(register_md_personality);
 EXPORT_SYMBOL(unregister_md_personality);
 EXPORT_SYMBOL(md_error);
#3 lore raw
In reply to NeilBrown
Quoted 4 lines · NeilBrown

I'd like to review the sysfs a bit more before it goes to Linus, but the rest can go anytime.

umm, what does "the sysfs" refer to?

Current md patches in -mm:

md-better-handling-of-readerrors-with-raid5.patch md-initial-sysfs-support-for-md.patch md-extend-md-sysfs-support-to-component-devices.patch md-add-kobject-sysfs-support-to-raid5.patch md-allow-a-manual-resync-with-md.patch md-teach-raid5-the-difference-between-check-and-repair.patch md-provide-proper-rcu_dereference--rcu_assign_pointer-annotations-in-md.patch md-fix-ref-counting-problems-with-kobjects-in-md.patch md-minor-md-fixes.patch md-change-raid5-sysfs-attribute-to-not-create-a-new-directory.patch md-improvements-to-raid5-handling-of-read-errors.patch md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field.patch md-make-md-on-disk-bitmaps-not-host-endian.patch md-support-bio_rw_barrier-for-md-raid1.patch drivers-md-fix-up-schedule_timeout-usage.patch

author
#4 lore raw
Quoted 7 lines · On Sunday October 30, [email protected] wrote:
Quoted 4 lines · NeilBrown

I'd like to review the sysfs a bit more before it goes to Linus, but the rest can go anytime.

umm, what does "the sysfs" refer to?

Sorry.. "the sysfs related patches".

Those marked as 'THIS' below.

However I think a couple that come after those won't simple move backwards (largely due to md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field).

I'll make sure you have a full set that I am happy to go to Linus by the end of the week.

Thanks,
NeilBrown

Quoted 4 lines

Current md patches in -mm:

md-better-handling-of-readerrors-with-raid5.patch

THIS > md-initial-sysfs-support-for-md.patch
THIS > md-extend-md-sysfs-support-to-component-devices.patch THIS > md-add-kobject-sysfs-support-to-raid5.patch
THIS > md-allow-a-manual-resync-with-md.patch
THIS > md-teach-raid5-the-difference-between-check-and-repair.patch

Quoted 1 line

md-provide-proper-rcu_dereference--rcu_assign_pointer-annotations-in-md.patch

THIS > md-fix-ref-counting-problems-with-kobjects-in-md.patch THIS > md-minor-md-fixes.patch
THIS > md-change-raid5-sysfs-attribute-to-not-create-a-new-directory.patch

Quoted 10 lines

md-improvements-to-raid5-handling-of-read-errors.patch md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field.patch md-make-md-on-disk-bitmaps-not-host-endian.patch md-support-bio_rw_barrier-for-md-raid1.patch drivers-md-fix-up-schedule_timeout-usage.patch

-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 12 lines · Neil Brown
Quoted 7 lines · On Sunday October 30, [email protected] wrote:
Quoted 4 lines · NeilBrown

I'd like to review the sysfs a bit more before it goes to Linus, but the rest can go anytime.

umm, what does "the sysfs" refer to?

Sorry.. "the sysfs related patches".

Quoted 8 lines

Those marked as 'THIS' below.

However I think a couple that come after those won't simple move backwards (largely due to md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field).

I'll make sure you have a full set that I am happy to go to Linus by the end of the week.

hm, OK, that's a bit late in the process to be introducing new material, so no later please.

Also, please make sure that Greg is copied on sysfs things - save me an email ;)

#6 lore raw
In reply to Neil Brown

Hello Neil , The original '[PATCH md 000 of 2] Introduction' never hit the list afaict . Could you please re-send or if you did & only I am without it send privately . Tia , JimL

Quoted 30 lines · Neil Brown
Quoted 4 lines · On Sunday October 30, [email protected] wrote:
Quoted 2 lines · NeilBrown

I'd like to review the sysfs a bit more before it goes to Linus, but the rest can go anytime.

umm, what does "the sysfs" refer to?

Sorry.. "the sysfs related patches".
Those marked as 'THIS' below.
However I think a couple that come after those won't simple move backwards (largely due to md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field). I'll make sure you have a full set that I am happy to go to Linus by the end of the week.
Thanks,
NeilBrown

Quoted 2 lines

Current md patches in -mm:
md-better-handling-of-readerrors-with-raid5.patch

THIS > md-initial-sysfs-support-for-md.patch
THIS > md-extend-md-sysfs-support-to-component-devices.patch THIS > md-add-kobject-sysfs-support-to-raid5.patch
THIS > md-allow-a-manual-resync-with-md.patch
THIS > md-teach-raid5-the-difference-between-check-and-repair.patch

Quoted 1 line

md-provide-proper-rcu_dereference--rcu_assign_pointer-annotations-in-md.patch

THIS > md-fix-ref-counting-problems-with-kobjects-in-md.patch THIS > md-minor-md-fixes.patch
THIS > md-change-raid5-sysfs-attribute-to-not-create-a-new-directory.patch

Quoted 5 lines

md-improvements-to-raid5-handling-of-read-errors.patch md-convert-faulty-and-in_sync-fields-to-bits-in-flags-field.patch md-make-md-on-disk-bitmaps-not-host-endian.patch md-support-bio_rw_barrier-for-md-raid1.patch drivers-md-fix-up-schedule_timeout-usage.patch

Signature · 5 lines
+------------------------------------------------------------------+
| James   W.   Laferriere | System    Techniques | Give me VMS     |
| Network        Engineer | 3542 Broken Yoke Dr. |  Give me Linux  |
| [email protected] | Billings , MT. 59105 |   only  on  AXP |
+------------------------------------------------------------------+