[PATCH 08/42] mkfs: factor log subopts parser

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

 



From: Dave Chinner <dchinner@xxxxxxxxxx>

Signed-Off-By: Dave Chinner <dchinner@xxxxxxxxxx>
---
 mkfs/xfs_mkfs.c | 127 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 65 insertions(+), 62 deletions(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index d702010c2854..8e42fe0301fb 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1607,6 +1607,48 @@ log_opts_parser(
 	char			*value,
 	struct cli_params	*cli)
 {
+	int			lsectorlog;
+
+	switch (subopt) {
+	case L_AGNUM:
+		cli->logagno = getnum(value, &lopts, L_AGNUM);
+		break;
+	case L_FILE:
+		cli->xi->lisfile = getnum(value, &lopts, L_FILE);
+		break;
+	case L_INTERNAL:
+		cli->loginternal = getnum(value, &lopts, L_INTERNAL);
+		break;
+	case L_SU:
+		cli->lsu = getstr(value, &lopts, L_SU);
+		break;
+	case L_SUNIT:
+		cli->lsunit = getnum(value, &lopts, L_SUNIT);
+		break;
+	case L_NAME:
+	case L_DEV:
+		cli->xi->logname = getstr(value, &lopts, L_NAME);
+		cli->loginternal = 0;
+		break;
+	case L_VERSION:
+		cli->sb_feat.log_version = getnum(value, &lopts, L_VERSION);
+		break;
+	case L_SIZE:
+		cli->logsize = getstr(value, &lopts, L_SIZE);
+		break;
+	case L_SECTLOG:
+		lsectorlog = getnum(value, &lopts, L_SECTLOG);
+		cli->lsectorsize = 1 << lsectorlog;
+		break;
+	case L_SECTSIZE:
+		cli->lsectorsize = getnum(value, &lopts, L_SECTSIZE);
+		break;
+	case L_LAZYSBCNTR:
+		cli->sb_feat.lazy_sb_counters = getnum(value, &lopts, L_LAZYSBCNTR);
+		break;
+	default:
+		return -EINVAL;
+	}
 	return 0;
 }
 
@@ -1910,70 +1952,31 @@ main(
 			/* end temp don't break code */
 			break;
 		case 'l':
-			p = optarg;
-			while (*p != '\0') {
-				char	**subopts = (char **)lopts.subopts;
-				char	*value;
+			parse_subopts(c, optarg, &cli);
 
-				switch (getsubopt(&p, subopts, &value)) {
-				case L_AGNUM:
-					logagno = getnum(value, &lopts, L_AGNUM);
-					laflag = 1;
-					break;
-				case L_FILE:
-					xi.lisfile = getnum(value, &lopts,
-							    L_FILE);
-					break;
-				case L_INTERNAL:
-					loginternal = getnum(value, &lopts,
-							     L_INTERNAL);
-					liflag = 1;
-					break;
-				case L_SU:
-					lsu = getnum(value, &lopts, L_SU);
-					lsuflag = 1;
-					break;
-				case L_SUNIT:
-					lsunit = getnum(value, &lopts, L_SUNIT);
-					lsunitflag = 1;
-					break;
-				case L_NAME:
-				case L_DEV:
-					logfile = getstr(value, &lopts, L_NAME);
-					xi.logname = logfile;
-					ldflag = 1;
-					loginternal = 0;
-					break;
-				case L_VERSION:
-					sb_feat.log_version =
-						getnum(value, &lopts, L_VERSION);
-					lvflag = 1;
-					break;
-				case L_SIZE:
-					logsize = getstr(value, &lopts, L_SIZE);
-					break;
-				case L_SECTLOG:
-					lsectorlog = getnum(value, &lopts,
-							    L_SECTLOG);
-					lsectorsize = 1 << lsectorlog;
-					lslflag = 1;
-					break;
-				case L_SECTSIZE:
-					lsectorsize = getnum(value, &lopts,
-							     L_SECTSIZE);
-					lsectorlog =
-						libxfs_highbit32(lsectorsize);
-					lssflag = 1;
-					break;
-				case L_LAZYSBCNTR:
-					sb_feat.lazy_sb_counters =
-							getnum(value, &lopts,
-							       L_LAZYSBCNTR);
-					break;
-				default:
-					unknown('l', value);
-				}
+			/* temp don't break code */
+			logagno = cli.logagno;
+			loginternal = cli.loginternal;
+			logfile = xi.logname;
+			logsize = cli.logsize;
+			lsectorsize = cli.lsectorsize;
+			lsectorlog = libxfs_highbit32(lsectorsize);
+
+			lsunit = cli.lsunit;
+			lsunitflag = cli_opt_set(&lopts, L_SUNIT);
+			if (cli_opt_set(&lopts, L_SU)) {
+				lsu = getnum(cli.lsu, &lopts, L_SU);
+				lsuflag = 1;
 			}
+
+			laflag = cli_opt_set(&lopts, L_AGNUM);
+			liflag = cli_opt_set(&lopts, L_INTERNAL);
+			ldflag = cli_opt_set(&lopts, L_NAME) ||
+				 cli_opt_set(&lopts, L_DEV);
+			lvflag = cli_opt_set(&lopts, L_VERSION);
+			lslflag = cli_opt_set(&lopts, L_SECTLOG);
+			lssflag = cli_opt_set(&lopts, L_SECTSIZE);
+			/* end temp don't break code */
 			break;
 		case 'L':
 			if (strlen(optarg) > sizeof(sbp->sb_fname))
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux