@@ -346,7 +346,7 @@ static void ovl_parse_param_drop_lowerdir(struct ovl_fs_context *ctx)
346
346
/*
347
347
* Parse lowerdir= mount option:
348
348
*
349
- * (1) lowerdir=/lower1:/lower2:/lower3::/data1::/data2
349
+ * e.g.: lowerdir=/lower1:/lower2:/lower3::/data1::/data2
350
350
* Set "/lower1", "/lower2", and "/lower3" as lower layers and
351
351
* "/data1" and "/data2" as data lower layers. Any existing lower
352
352
* layers are replaced.
@@ -356,20 +356,20 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
356
356
int err ;
357
357
struct ovl_fs_context * ctx = fc -> fs_private ;
358
358
struct ovl_fs_context_layer * l ;
359
- char * dup = NULL , * dup_iter ;
359
+ char * dup = NULL , * iter ;
360
360
ssize_t nr_lower = 0 , nr = 0 , nr_data = 0 ;
361
- bool append = false, data_layer = false;
361
+ bool data_layer = false;
362
362
363
363
/*
364
364
* Ensure we're backwards compatible with mount(2)
365
365
* by allowing relative paths.
366
366
*/
367
367
368
368
/* drop all existing lower layers */
369
- if (!* name ) {
370
- ovl_parse_param_drop_lowerdir (ctx );
369
+ ovl_parse_param_drop_lowerdir (ctx );
370
+
371
+ if (!* name )
371
372
return 0 ;
372
- }
373
373
374
374
if (* name == ':' ) {
375
375
pr_err ("cannot append lower layer" );
@@ -385,36 +385,11 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
385
385
if (nr_lower < 0 )
386
386
goto out_err ;
387
387
388
- if ((nr_lower > OVL_MAX_STACK ) ||
389
- (append && (size_add (ctx -> nr , nr_lower ) > OVL_MAX_STACK ))) {
388
+ if (nr_lower > OVL_MAX_STACK ) {
390
389
pr_err ("too many lower directories, limit is %d\n" , OVL_MAX_STACK );
391
390
goto out_err ;
392
391
}
393
392
394
- if (!append )
395
- ovl_parse_param_drop_lowerdir (ctx );
396
-
397
- /*
398
- * (1) append
399
- *
400
- * We want nr <= nr_lower <= capacity We know nr > 0 and nr <=
401
- * capacity. If nr == 0 this wouldn't be append. If nr +
402
- * nr_lower is <= capacity then nr <= nr_lower <= capacity
403
- * already holds. If nr + nr_lower exceeds capacity, we realloc.
404
- *
405
- * (2) replace
406
- *
407
- * Ensure we're backwards compatible with mount(2) which allows
408
- * "lowerdir=/a:/b:/c,lowerdir=/d:/e:/f" causing the last
409
- * specified lowerdir mount option to win.
410
- *
411
- * We want nr <= nr_lower <= capacity We know either (i) nr == 0
412
- * or (ii) nr > 0. We also know nr_lower > 0. The capacity
413
- * could've been changed multiple times already so we only know
414
- * nr <= capacity. If nr + nr_lower > capacity we realloc,
415
- * otherwise nr <= nr_lower <= capacity holds already.
416
- */
417
- nr_lower += ctx -> nr ;
418
393
if (nr_lower > ctx -> capacity ) {
419
394
err = - ENOMEM ;
420
395
l = krealloc_array (ctx -> lower , nr_lower , sizeof (* ctx -> lower ),
@@ -426,41 +401,17 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
426
401
ctx -> capacity = nr_lower ;
427
402
}
428
403
429
- /*
430
- * (3) By (1) and (2) we know nr <= nr_lower <= capacity.
431
- * (4) If ctx->nr == 0 => replace
432
- * We have verified above that the lowerdir mount option
433
- * isn't an append, i.e., the lowerdir mount option
434
- * doesn't start with ":" or "::".
435
- * (4.1) The lowerdir mount options only contains regular lower
436
- * layers ":".
437
- * => Nothing to verify.
438
- * (4.2) The lowerdir mount options contains regular ":" and
439
- * data "::" layers.
440
- * => We need to verify that data lower layers "::" aren't
441
- * followed by regular ":" lower layers
442
- * (5) If ctx->nr > 0 => append
443
- * We know that there's at least one regular layer
444
- * otherwise we would've failed when parsing the previous
445
- * lowerdir mount option.
446
- * (5.1) The lowerdir mount option is a regular layer ":" append
447
- * => We need to verify that no data layers have been
448
- * specified before.
449
- * (5.2) The lowerdir mount option is a data layer "::" append
450
- * We know that there's at least one regular layer or
451
- * other data layers. => There's nothing to verify.
452
- */
453
- dup_iter = dup ;
454
- for (nr = ctx -> nr ; nr < nr_lower ; nr ++ ) {
455
- l = & ctx -> lower [nr ];
404
+ iter = dup ;
405
+ l = ctx -> lower ;
406
+ for (nr = 0 ; nr < nr_lower ; nr ++ , l ++ ) {
456
407
memset (l , 0 , sizeof (* l ));
457
408
458
- err = ovl_mount_dir (dup_iter , & l -> path , false);
409
+ err = ovl_mount_dir (iter , & l -> path , false);
459
410
if (err )
460
411
goto out_put ;
461
412
462
413
err = - ENOMEM ;
463
- l -> name = kstrdup (dup_iter , GFP_KERNEL_ACCOUNT );
414
+ l -> name = kstrdup (iter , GFP_KERNEL_ACCOUNT );
464
415
if (!l -> name )
465
416
goto out_put ;
466
417
@@ -472,8 +423,8 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
472
423
break ;
473
424
474
425
err = - EINVAL ;
475
- dup_iter = strchr (dup_iter , '\0' ) + 1 ;
476
- if (* dup_iter ) {
426
+ iter = strchr (iter , '\0' ) + 1 ;
427
+ if (* iter ) {
477
428
/*
478
429
* This is a regular layer so we require that
479
430
* there are no data layers.
@@ -489,29 +440,15 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
489
440
490
441
/* This is a data lower layer. */
491
442
data_layer = true;
492
- dup_iter ++ ;
443
+ iter ++ ;
493
444
}
494
445
ctx -> nr = nr_lower ;
495
446
ctx -> nr_data += nr_data ;
496
447
kfree (dup );
497
448
return 0 ;
498
449
499
450
out_put :
500
- /*
501
- * We know nr >= ctx->nr < nr_lower. If we failed somewhere
502
- * we want to undo until nr == ctx->nr. This is correct for
503
- * both ctx->nr == 0 and ctx->nr > 0.
504
- */
505
- for (; nr >= ctx -> nr ; nr -- ) {
506
- l = & ctx -> lower [nr ];
507
- kfree (l -> name );
508
- l -> name = NULL ;
509
- path_put (& l -> path );
510
-
511
- /* don't overflow */
512
- if (nr == 0 )
513
- break ;
514
- }
451
+ ovl_parse_param_drop_lowerdir (ctx );
515
452
516
453
out_err :
517
454
kfree (dup );
0 commit comments