5
5
6
6
#include "kublk.h"
7
7
8
+ #define MAX_NR_TGT_ARG 64
9
+
8
10
unsigned int ublk_dbg_mask = UBLK_LOG ;
9
11
static const struct ublk_tgt_ops * tgt_ops_list [] = {
10
12
& null_tgt_ops ,
@@ -1202,12 +1204,25 @@ static int cmd_dev_get_features(void)
1202
1204
1203
1205
static int cmd_dev_help (char * exe )
1204
1206
{
1205
- printf ("%s add -t [null|loop] [-q nr_queues] [-d depth] [-n dev_id] [backfile1] [backfile2] ...\n" , exe );
1206
- printf ("\t default: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n" );
1207
+ int i ;
1208
+
1209
+ printf ("%s add -t [null|loop|stripe] [-q nr_queues] [-d depth] [-n dev_id]\n" , exe );
1210
+ printf ("\t[--foreground] [--quiet] [-z] [--debug_mask mask]\n" );
1211
+ printf ("\t[target options] [backfile1] [backfile2] ...\n" );
1212
+ printf ("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n" );
1213
+
1214
+ for (i = 0 ; i < sizeof (tgt_ops_list ) / sizeof (tgt_ops_list [0 ]); i ++ ) {
1215
+ const struct ublk_tgt_ops * ops = tgt_ops_list [i ];
1216
+
1217
+ if (ops -> usage )
1218
+ ops -> usage (ops );
1219
+ }
1220
+ printf ("\n" );
1221
+
1207
1222
printf ("%s del [-n dev_id] -a \n" , exe );
1208
- printf ("\t -a delete all devices -n delete specified device\n" );
1223
+ printf ("\t -a delete all devices -n delete specified device\n\n " );
1209
1224
printf ("%s list [-n dev_id] -a \n" , exe );
1210
- printf ("\t -a list all devices, -n list specified device, default -a \n" );
1225
+ printf ("\t -a list all devices, -n list specified device, default -a \n\n " );
1211
1226
printf ("%s features\n" , exe );
1212
1227
return 0 ;
1213
1228
}
@@ -1224,23 +1239,25 @@ int main(int argc, char *argv[])
1224
1239
{ "quiet" , 0 , NULL , 0 },
1225
1240
{ "zero_copy" , 0 , NULL , 'z' },
1226
1241
{ "foreground" , 0 , NULL , 0 },
1227
- { "chunk_size" , 1 , NULL , 0 },
1228
1242
{ 0 , 0 , 0 , 0 }
1229
1243
};
1244
+ const struct ublk_tgt_ops * ops = NULL ;
1230
1245
int option_idx , opt ;
1231
1246
const char * cmd = argv [1 ];
1232
1247
struct dev_ctx ctx = {
1233
1248
.queue_depth = 128 ,
1234
1249
.nr_hw_queues = 2 ,
1235
1250
.dev_id = -1 ,
1236
1251
.tgt_type = "unknown" ,
1237
- .chunk_size = 65536 , /* def chunk size is 64K */
1238
1252
};
1239
1253
int ret = - EINVAL , i ;
1254
+ int tgt_argc = 1 ;
1255
+ char * tgt_argv [MAX_NR_TGT_ARG ] = { NULL };
1240
1256
1241
1257
if (argc == 1 )
1242
1258
return ret ;
1243
1259
1260
+ opterr = 0 ;
1244
1261
optind = 2 ;
1245
1262
while ((opt = getopt_long (argc , argv , "t:n:d:q:az" ,
1246
1263
longopts , & option_idx )) != -1 ) {
@@ -1271,8 +1288,26 @@ int main(int argc, char *argv[])
1271
1288
ublk_dbg_mask = 0 ;
1272
1289
if (!strcmp (longopts [option_idx ].name , "foreground" ))
1273
1290
ctx .fg = 1 ;
1274
- if (!strcmp (longopts [option_idx ].name , "chunk_size" ))
1275
- ctx .chunk_size = strtol (optarg , NULL , 10 );
1291
+ break ;
1292
+ case '?' :
1293
+ /*
1294
+ * target requires every option must have argument
1295
+ */
1296
+ if (argv [optind ][0 ] == '-' || argv [optind - 1 ][0 ] != '-' ) {
1297
+ fprintf (stderr , "every target option requires argument: %s %s\n" ,
1298
+ argv [optind - 1 ], argv [optind ]);
1299
+ exit (EXIT_FAILURE );
1300
+ }
1301
+
1302
+ if (tgt_argc < (MAX_NR_TGT_ARG - 1 ) / 2 ) {
1303
+ tgt_argv [tgt_argc ++ ] = argv [optind - 1 ];
1304
+ tgt_argv [tgt_argc ++ ] = argv [optind ];
1305
+ } else {
1306
+ fprintf (stderr , "too many target options\n" );
1307
+ exit (EXIT_FAILURE );
1308
+ }
1309
+ optind += 1 ;
1310
+ break ;
1276
1311
}
1277
1312
}
1278
1313
@@ -1281,6 +1316,14 @@ int main(int argc, char *argv[])
1281
1316
ctx .files [ctx .nr_files ++ ] = argv [i ++ ];
1282
1317
}
1283
1318
1319
+ ops = ublk_find_tgt (ctx .tgt_type );
1320
+ if (ops && ops -> parse_cmd_line ) {
1321
+ optind = 0 ;
1322
+
1323
+ tgt_argv [0 ] = ctx .tgt_type ;
1324
+ ops -> parse_cmd_line (& ctx , tgt_argc , tgt_argv );
1325
+ }
1326
+
1284
1327
if (!strcmp (cmd , "add" ))
1285
1328
ret = cmd_dev_add (& ctx );
1286
1329
else if (!strcmp (cmd , "del" ))
0 commit comments