Skip to contentSkip to conversation

dynamic creation/removal more then 256 drbd devices

PATCH In review Stanislaw Gruszka 2 participants 6 messages Apr 27, 2007 – May 7, 2007 DRBD driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dynamic creation/removal more then 256 drbd devices

Hallo,

I did patch for dynamic creation/removal drbd devices. Drbd have already dynamic drbd creation, but no removal. Also my patch breaks limit of 256 drbd devices - linked list is used for keeping devices; minor_table is removed, idr structure form include/linux/idr.h is used instead. Please comment. Is there a chance it will be applied?

Patch is divided into 2 parts: kernel and user space.

Signature · 2 lines
Regards
Stanislaw Gruszka
drbd/drbd_proc.c +8 -14
Index: trunk/drbd/drbd_proc.c
===================================================================
@@ -172,9 +172,9 @@
 
 STATIC int drbd_seq_show(struct seq_file *seq, void *v)
 {
-	int i,hole=0;
 	const char *sn;
 	drbd_dev *mdev;
+	struct list_head *p;
 
 	seq_printf(seq, "version: " REL_VERSION " (api:%d/proto:%d)\n%s\n",
 		    API_VERSION,PRO_VERSION, drbd_buildtag());
@@ -192,28 +192,22 @@
 	  al .. access log write count
 	*/
 
-	for (i = 0; i < minor_count; i++) {
-		mdev = minor_to_mdev(i);
-		if(!mdev) {
-			hole=1;
-			continue;
-		}
-		if( hole ) {
-			hole=0;
-			seq_printf( seq, "\n");
-		}
+	down(&drbd_devs_mutex);
+	list_for_each(p, &drbd_devs_list) {
+		mdev = list_entry(p, struct Drbd_Conf, devs_list);
 
 		sn = conns_to_name(mdev->state.conn);
 
 		if ( mdev->state.conn == StandAlone &&
 		     mdev->state.disk == Diskless) {
-			seq_printf( seq, "%2d: cs:Unconfigured\n", i);
+			seq_printf( seq, "%2d: cs:Unconfigured\n",
+			  mdev_to_minor(mdev));
 		} else {
 			seq_printf( seq,
 			   "%2d: cs:%s st:%s/%s ds:%s/%s %c %c%c%c%c\n"
 			   "    ns:%u nr:%u dw:%u dr:%u al:%u bm:%u "
 			   "lo:%d pe:%d ua:%d ap:%d\n",
-			   i, sn,
+			   mdev_to_minor(mdev), sn,
 			   roles_to_name(mdev->state.role),
 			   roles_to_name(mdev->state.peer),
 			   disks_to_name(mdev->state.disk),
@@ -255,7 +249,7 @@
 #endif
 
 	}
-
+	up(&drbd_devs_mutex);
 	return 0;
 }
 
drbd/drbd_receiver.c +1 -1
Index: trunk/drbd/drbd_receiver.c
===================================================================
@@ -194,7 +194,7 @@
 	int free_it;
 
 	spin_lock_irqsave(&drbd_pp_lock,flags);
-	if (drbd_pp_vacant > (DRBD_MAX_SEGMENT_SIZE/PAGE_SIZE)*minor_count) {
+	if (drbd_pp_vacant > (DRBD_MAX_SEGMENT_SIZE/PAGE_SIZE)*prealloc_segments) {
 		free_it = 1;
 	} else {
 		set_page_private(page, (unsigned long)drbd_pp_pool);
drbd/drbd_worker.c +16 -12
Index: trunk/drbd/drbd_worker.c
===================================================================
@@ -714,11 +714,12 @@
 STATIC void drbd_global_lock(void)
 {
 	drbd_dev *mdev;
-	int i;
+	struct list_head *p;
 
+	down(&drbd_devs_mutex);
 	local_irq_disable();
-	for (i=0; i < minor_count; i++) {
-		if(!(mdev = minor_to_mdev(i))) continue;
+	list_for_each(p, &drbd_devs_list) {
+		mdev = list_entry(p, struct Drbd_Conf, devs_list);
 		spin_lock(&mdev->req_lock);
 	}
 }
@@ -726,13 +727,14 @@
 STATIC void drbd_global_unlock(void)
 {
 	drbd_dev *mdev;
-	int i;
+	struct list_head *p;
 
-	for (i=0; i < minor_count; i++) {
-		if(!(mdev = minor_to_mdev(i))) continue;
+	list_for_each(p, &drbd_devs_list) {
+		mdev = list_entry(p, struct Drbd_Conf, devs_list);
 		spin_unlock(&mdev->req_lock);
 	}
 	local_irq_enable();
+	up(&drbd_devs_mutex);;
 }
 
 STATIC int _drbd_may_sync_now(drbd_dev *mdev)
@@ -759,10 +761,11 @@
 STATIC int _drbd_pause_after(drbd_dev *mdev)
 {
 	drbd_dev *odev;
-	int i, rv = 0;
+	struct list_head *p;
+	int rv = 0;
 
-	for (i=0; i < minor_count; i++) {
-		if( !(odev = minor_to_mdev(i)) ) continue;
+	list_for_each(p, &drbd_devs_list) {
+		odev = list_entry(p, struct Drbd_Conf, devs_list); 
 		if (! _drbd_may_sync_now(odev)) {
 			rv |= ( _drbd_set_state(_NS(odev,aftr_isp,1),
 						ChgStateHard|ScheduleAfter)
@@ -782,10 +785,11 @@
 STATIC int _drbd_resume_next(drbd_dev *mdev)
 {
 	drbd_dev *odev;
-	int i, rv = 0;
+	struct list_head *p;
+	int rv = 0;
 
-	for (i=0; i < minor_count; i++) {
-		if( !(odev = minor_to_mdev(i)) ) continue;
+	list_for_each(p, &drbd_devs_list) {
+		odev = list_entry(p, struct Drbd_Conf, devs_list);
 		if ( odev->state.aftr_isp ) {
 			if (_drbd_may_sync_now(odev)) {
 				rv |= ( _drbd_set_state(_NS(odev,aftr_isp,0),
drbd/drbd_nl.c +39 -30

127 lines not on this page · raw message

drbd/linux/drbd.h +3 -0
Index: trunk/drbd/linux/drbd.h
===================================================================
@@ -113,6 +113,9 @@
 	HaveNoDiskConfig,
 	ProtocolCRequired,
 
+	MinorInUse,
+	MinorInvalid,
+
 	/* insert new ones above this line */
 	AfterLastRetCode
 };
drbd/linux/drbd_nl.h +3 -0
Index: trunk/drbd/linux/drbd_nl.h
===================================================================
@@ -90,6 +90,9 @@
 	STRING(		38,	T_MAY_IGNORE,	helper,		32)
 )
 
+PACKET(create, 21, )
+PACKET(remove, 22, )
+
 #undef PACKET
 #undef INTEGER
 #undef INT64
drbd/drbd_main.c +242 -152

535 lines not on this page · raw message

drbd/drbd_req.c +2 -1
Index: trunk/drbd/drbd_req.c
===================================================================
@@ -1110,7 +1110,8 @@
 		/* rather error out here than BUG in bio_split */
 		ERR("bio would need to, but cannot, be split: "
 		    "(vcnt=%u,idx=%u,size=%u,sector=%llu)\n",
-		    bio->bi_vcnt, bio->bi_idx, bio->bi_size, bio->bi_sector);
+		    bio->bi_vcnt, bio->bi_idx, bio->bi_size,
+		    (unsigned long long) bio->bi_sector);
 		bio_endio(bio, bio->bi_size, -EINVAL);
 		return 0;
 	} else {
drbd/drbd_int.h +12 -12
Index: trunk/drbd/drbd_int.h
===================================================================
@@ -40,7 +40,6 @@
 #include "lru_cache.h"
 
 // module parameter, defined in drbd_main.c
-extern int minor_count;
 extern int allow_oos;
 extern int major_nr;
 extern int use_nbd_major;
@@ -141,7 +140,7 @@
 //       Otherwise this is not portable from gcc-2.95 to gcc-3.3
 #define PRINTK(level,fmt,args...) \
 	printk(level DEVICE_NAME "%d: " fmt, \
-		mdev->minor , ##args)
+		mdev_to_minor(mdev) , ##args)
 
 #define ALERT(fmt,args...) PRINTK(KERN_ALERT, fmt , ##args)
 #define ERR(fmt,args...)  PRINTK(KERN_ERR, fmt , ##args)
@@ -263,7 +262,6 @@
 /* drbd_meta-data.c (still in drbd_main.c) */
 #define DRBD_MD_MAGIC (DRBD_MAGIC+4) // 4th incarnation of the disk layout.
 
-extern struct Drbd_Conf **minor_table;
 
 /***
  * on the wire
@@ -861,22 +859,23 @@
 	atomic_t packet_seq;
 	unsigned int peer_seq;
 	spinlock_t peer_seq_lock;
-	int minor;
 	unsigned long comm_bm_set; // communicated number of set bits.
+
+	struct list_head devs_list;
 };
 
+extern struct semaphore drbd_devs_mutex;
+extern struct list_head drbd_devs_list;
+extern drbd_dev *drbd_find_minor(int minor);
+
 static inline drbd_dev *minor_to_mdev(int minor)
 {
-	drbd_dev *mdev;
-
-	mdev = minor < minor_count ? minor_table[minor] : NULL;
-
-	return mdev;
+	return drbd_find_minor(minor);
 }
 
 static inline int mdev_to_minor(drbd_dev *mdev)
 {
-	return mdev->minor;
+	return mdev->vdisk->first_minor;
 }
 
 /* returns 1 if it was successfull,
@@ -1165,7 +1164,6 @@
  * because of kmem_cache_t weirdness */
 #include "drbd_compat_wrappers.h"
 
-extern int minor_count;
 extern drbd_kmem_cache_t *drbd_request_cache;
 extern drbd_kmem_cache_t *drbd_ee_cache;
 extern mempool_t *drbd_request_mempool;
@@ -1175,8 +1173,10 @@
 extern spinlock_t   drbd_pp_lock;
 extern int          drbd_pp_vacant;
 extern wait_queue_head_t drbd_pp_wait;
+extern unsigned int prealloc_segments;
 
-extern drbd_dev *drbd_new_device(int minor);
+extern int drbd_create_device(int minor);
+extern int drbd_remove_device(drbd_dev *mdev);
 
 // Dynamic tracing framework
 #ifdef ENABLE_DYNAMIC_TRACE
user/drbdadm_main.c +23 -5
Index: trunk/user/drbdadm_main.c
===================================================================
@@ -85,6 +85,7 @@
 extern int yydebug;
 extern FILE* yyin;
 
+int adm_create(struct d_resource* ,const char* );
 int adm_attach(struct d_resource* ,const char* );
 int adm_connect(struct d_resource* ,const char* );
 int adm_generic_s(struct d_resource* ,const char* );
@@ -134,7 +135,7 @@
 int soi=0;
 volatile int alarm_raised;
 
-struct deferred_cmd *deferred_cmds[3] = { NULL, NULL, NULL };
+struct deferred_cmd *deferred_cmds[4] = { NULL, NULL, NULL, NULL };
 
 void schedule_dcmd( int (* function)(struct d_resource*,const char* ),
 		    struct d_resource* res,
@@ -180,7 +181,8 @@
 {
   return _run_dcmds(deferred_cmds[0]) ||
     _run_dcmds(deferred_cmds[1]) ||
-    _run_dcmds(deferred_cmds[2]);
+    _run_dcmds(deferred_cmds[2]) ||
+    _run_dcmds(deferred_cmds[3]);
 }
 
 struct option admopt[] = {
@@ -194,6 +196,8 @@
 
 struct adm_cmd cmds[] = {
 /*   name, function,                  show, needs res, verify_ips */
+  { "create",		 adm_create,    1,1,0 },
+  { "remove",		 adm_generic_s, 1,1,0 },
   { "attach",            adm_attach,    1,1,0 },
   { "detach",            adm_generic_s, 1,1,0 },
   { "connect",           adm_connect,   1,1,1 },
@@ -759,6 +763,19 @@
     OPT=OPT->next; \
   }
 
+int adm_create(struct d_resource* res,const char* unused __attribute((unused)))
+{
+  char* argv[MAX_ARGS];
+  int argc=0;
+
+  argv[NA(argc)]=drbdsetup;
+  argv[NA(argc)]=res->me->device;
+  argv[NA(argc)]="create";
+  argv[NA(argc)]=0;
+
+  return m_system(argv,SLEEPS_LONG);
+}
+
 int adm_attach(struct d_resource* res,const char* unused __attribute((unused)))
 {
   char* argv[MAX_ARGS];
@@ -995,9 +1012,10 @@
 
 static int adm_up(struct d_resource* res,const char* unused __attribute((unused)))
 {
-  schedule_dcmd(adm_attach,res,NULL,0);
-  schedule_dcmd(adm_syncer,res,NULL,1);
-  schedule_dcmd(adm_connect,res,NULL,2);
+  schedule_dcmd(adm_create,res,NULL,0);
+  schedule_dcmd(adm_attach,res,NULL,1);
+  schedule_dcmd(adm_syncer,res,NULL,2);
+  schedule_dcmd(adm_connect,res,NULL,3);
 
   return 0;
 }
user/drbdsetup.c +13 -3
Index: trunk/user/drbdsetup.c
===================================================================
@@ -347,6 +347,8 @@
 		wait_cmds_options, w_connected_state } } },
 	{"wait-sync", 0, F_EVENTS_CMD, { .ep = {
 		wait_cmds_options, w_synced_state } } },
+	{"create", P_create, F_CONFIG_CMD, {{NULL, NULL}}},
+	{"remove", P_remove, F_CONFIG_CMD, {{NULL, NULL}}},
 };
 
 #define EM(C) [ C - RetCodeBase ]
@@ -393,7 +395,9 @@
 	EM(PauseFlagAlreadyClear) = "Sync-pause flag is already cleared",
 	EM(DiskLowerThanOutdated) = "Disk state is lower than outdated",
 	EM(HaveNoDiskConfig) = "Device does not have a disk-config",
-	EM(ProtocolCRequired) = "Protocol C required"
+	EM(ProtocolCRequired) = "Protocol C required",
+	EM(MinorInUse) = "Minor number in use.",
+	EM(MinorInvalid) = "Minor number invalid."
 };
 #define MAX_ERROR (sizeof(error_messages)/sizeof(*error_messages))
 const char * error_to_string(int err_no)
@@ -1170,11 +1174,17 @@
 	cm = find_cmd_by_name("secondary");
 	rv = cm->function(cm,minor,argc,argv);
 	if( rv ) return rv;
+
 	cm = find_cmd_by_name("disconnect");
-	cm->function(cm,minor,argc,argv);
+	rv = cm->function(cm,minor,argc,argv);	
+	if ( rv ) return rv;
+
 	cm = find_cmd_by_name("detach");
-	rv |= cm->function(cm,minor,argc,argv);
+	rv = cm->function(cm,minor,argc,argv);
+	if( rv ) return rv;
 
+	cm = find_cmd_by_name("remove");
+	rv = cm->function(cm,minor,argc,argv);
 	return rv;
 }
 
maintainer
#1 lore raw

Am Freitag, 27. April 2007 11:21 schrieb Stanislaw Gruszka:

Quoted 10 lines

Hallo,

I did patch for dynamic creation/removal drbd devices. Drbd have already dynamic drbd creation, but no removal. Also my patch breaks limit of 256 drbd devices - linked list is used for keeping devices; minor_table is removed, idr structure form include/linux/idr.h is used instead. Please comment. Is there a chance it will be applied?

Patch is divided into 2 parts: kernel and user space.

Hi Stanislaw,

We are just looking at the patch and are wondering why one would like to have more than 256 devices ?

-Phil

Signature · 3 lines
: Dipl-Ing Philipp Reisner                      Tel +43-1-8178292-50 :
: LINBIT Information Technologies GmbH          Fax +43-1-8178292-82 :
: Vivenotgasse 48, 1120 Vienna, Austria        http://www.linbit.com :
#2 lore raw
Quoted 2 lines · Philipp Reisner

We are just looking at the patch and are wondering why one would like to have more than 256 devices ?

Philipp,

With LVM it is possible to create many logical volumes. One may want to create a lot of (small) logical volumes and use them as backing devices for drbd for replication to some hosts with also a lot of logical volumes. Now drbd have flexible meta data so replication of small size block devices have sense. Someone may want to make replication on many small devices.

Signature · 2 lines
Cheers
Stanislaw Gruszka
maintainer
#3 lore raw

Am Freitag, 4. Mai 2007 13:36 schrieb Stanislaw Gruszka:

Quoted 6 lines · Philipp Reisner
Quoted 2 lines

We are just looking at the patch and are wondering why one would like to have more than 256 devices ?

Philipp,

Quoted 7 lines

With LVM it is possible to create many logical volumes. One may want to create a lot of (small) logical volumes and use them as backing devices for drbd for replication to some hosts with also a lot of logical volumes. Now drbd have flexible meta data so replication of small size block devices have sense. Someone may want to make replication on many small devices.

Yes of course.

But in case I had an application that is in the need for many block devices (e.g. a farm of kvm or xen instances...) I would put a LVM VG on top of a singe DRBD device.

My question is more like: What was your motivation for doing this patch ?

-Phil

Signature · 3 lines
: Dipl-Ing Philipp Reisner                      Tel +43-1-8178292-50 :
: LINBIT Information Technologies GmbH          Fax +43-1-8178292-82 :
: Vivenotgasse 48, 1120 Vienna, Austria        http://www.linbit.com :
#4 lore raw
Quoted 3 lines · Philipp Reisner

But in case I had an application that is in the need for many block devices (e.g. a farm of kvm or xen instances...) I would put a LVM VG on top of a singe DRBD device.

IMHO creating drbd on top lv's is more flexible then creating vg on top of drbd, however this depend on overall system design and needs.

Quoted 2 lines

My question is more like: What was your motivation for doing this patch ?

Well, my boss want me to do it. My company provide linux based software to storage servers and some client wont it.

Signature · 2 lines
Cheers
Stanislaw Gruszka
maintainer
#5 lore raw
Quoted 5 lines · On Monday 07 May 2007 09:20:49 Stanislaw Gruszka wrote:
Quoted 3 lines · Philipp Reisner

But in case I had an application that is in the need for many block devices (e.g. a farm of kvm or xen instances...) I would put a LVM VG on top of a singe DRBD device.

Quoted 8 lines

IMHO creating drbd on top lv's is more flexible then creating vg on top of drbd, however this depend on overall system design and needs.

Quoted 2 lines

My question is more like: What was your motivation for doing this patch ?

Well, my boss want me to do it. My company provide linux based software to storage servers and some client wont it.

Hi Stanislaw,

I will review and commit your stuff to SVN soon after the 8.0.3 release. I.e. you patch will probably be included in the 8.0.4 release.

-phil

Signature · 3 lines
: Dipl-Ing Philipp Reisner                      Tel +43-1-8178292-50 :
: LINBIT Information Technologies GmbH          Fax +43-1-8178292-82 :
: Vivenotgasse 48, 1120 Vienna, Austria        http://www.linbit.com :