[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[dm-devel] [Patch 1/1] dm-mpath.c: tidy status method



dm-mpath.c: define an EMIT macro to tidy the status method a bit

--- diff/drivers/md/dm-mpath.c	2004-02-25 13:29:18.000000000 +0000
+++ source/drivers/md/dm-mpath.c	2004-02-25 13:00:00.000000000 +0000
@@ -631,55 +631,44 @@ static int multipath_status(struct dm_ta
 	struct path *p;
 	char buffer[32];
 
+#define EMIT(x...) sz += ((sz >= maxlen) ? \
+			  0 : snprintf(result + sz, maxlen - sz, x))
+
 	switch (type) {
 	case STATUSTYPE_INFO:
-		sz += snprintf(result + sz, maxlen - sz, "%u ", m->nr_priority_groups);
+		EMIT("%u ", m->nr_priority_groups);
 
 		list_for_each_entry(pg, &m->priority_groups, list) {
-			sz += snprintf(result + sz, maxlen - sz, "%u %u ",
-                                       pg->nr_paths,
-				       pg->ps->type->info_args);
+			EMIT("%u %u ", pg->nr_paths, pg->ps->type->info_args);
 
 			list_for_each_entry(p, &pg->paths, list) {
 				format_dev_t(buffer, p->dev->bdev->bd_dev);
 				spin_lock_irqsave(&p->failed_lock, flags);
-				sz += snprintf(result + sz, maxlen - sz,
-					       "%s %s %u ", buffer,
-					       p->has_failed ? "F" : "A",
-					       p->fail_count);
+				EMIT("%s %s %u ", buffer,
+				     p->has_failed ? "F" : "A", p->fail_count);
 				pg->ps->type->status(pg->ps, p, type,
 						     result + sz, maxlen - sz);
 				spin_unlock_irqrestore(&p->failed_lock, flags);
-
-				sz = strlen(result);
-				if (sz >= maxlen)
-					break;
 			}
 		}
-
 		break;
 
 	case STATUSTYPE_TABLE:
-		sz += snprintf(result + sz, maxlen - sz, "%u ", m->nr_priority_groups);
+		EMIT("%u ", m->nr_priority_groups);
 
 		list_for_each_entry(pg, &m->priority_groups, list) {
-			sz += snprintf(result + sz, maxlen - sz, "%u %s %u %u ",
-				       pg->priority, pg->ps->type->name,
-				       pg->nr_paths, pg->ps->type->table_args);
+			EMIT("%u %s %u %u ",
+			     pg->priority, pg->ps->type->name,
+			     pg->nr_paths, pg->ps->type->table_args);
 
 			list_for_each_entry(p, &pg->paths, list) {
 				format_dev_t(buffer, p->dev->bdev->bd_dev);
-				sz += snprintf(result + sz, maxlen - sz,
-					       "%s ", buffer);
+				EMIT("%s ", buffer);
 				pg->ps->type->status(pg->ps, p, type,
 						     result + sz, maxlen - sz);
 
-				sz = strlen(result);
-				if (sz >= maxlen)
-					break;
 			}
 		}
-
 		break;
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]