Lines Matching +full:lower +full:- +full:case

1 // SPDX-License-Identifier: GPL-2.0-only
80 return ovl_parameter_uuid[config->uuid].name; in ovl_uuid_mode()
97 return ovl_parameter_xino[config->xino].name; in ovl_xino_mode()
115 return ovl_parameter_redirect_dir[config->redirect_mode].name; in ovl_redirect_mode()
134 return ovl_parameter_verity[config->verity_mode].name; in ovl_verity_mode()
208 return -EINVAL; in ovl_parse_param_split_lowerdirs()
223 return -EINVAL; in ovl_parse_param_split_lowerdirs()
235 int err = -EINVAL; in ovl_mount_dir_noesc()
267 int err = -ENOMEM; in ovl_mount_dir()
281 struct ovl_fs_context *ctx = fc->fs_private; in ovl_mount_dir_check()
283 if (!d_is_dir(path->dentry)) in ovl_mount_dir_check()
287 * Root dentries of case-insensitive capable filesystems might in ovl_mount_dir_check()
289 * with overlayfs. Check explicitly to prevent post-mount in ovl_mount_dir_check()
292 if (sb_has_encoding(path->mnt->mnt_sb)) in ovl_mount_dir_check()
293 return invalfc(fc, "case-insensitive capable filesystem on %s not supported", name); in ovl_mount_dir_check()
295 if (ovl_dentry_weird(path->dentry)) in ovl_mount_dir_check()
299 * Check whether upper path is read-only here to report failures in ovl_mount_dir_check()
304 if (path->dentry->d_flags & DCACHE_OP_REAL) in ovl_mount_dir_check()
306 if (__mnt_is_readonly(path->mnt)) in ovl_mount_dir_check()
307 return invalfc(fc, "filesystem on %s is read-only", name); in ovl_mount_dir_check()
309 if (ctx->lowerdir_all && layer != Opt_lowerdir) in ovl_mount_dir_check()
311 if (ctx->nr_data && layer == Opt_lowerdir_add) in ovl_mount_dir_check()
312 return invalfc(fc, "regular lower layers cannot follow data layers"); in ovl_mount_dir_check()
313 if (ctx->nr == OVL_MAX_STACK) in ovl_mount_dir_check()
314 return invalfc(fc, "too many lower directories, limit is %d", in ovl_mount_dir_check()
322 struct ovl_fs_context *ctx = fc->fs_private; in ovl_ctx_realloc_lower()
326 if (ctx->nr < ctx->capacity) in ovl_ctx_realloc_lower()
329 nr = min_t(size_t, max(4096 / sizeof(*l), ctx->capacity * 2), in ovl_ctx_realloc_lower()
331 l = krealloc_array(ctx->lower, nr, sizeof(*l), GFP_KERNEL_ACCOUNT); in ovl_ctx_realloc_lower()
333 return -ENOMEM; in ovl_ctx_realloc_lower()
335 ctx->lower = l; in ovl_ctx_realloc_lower()
336 ctx->capacity = nr; in ovl_ctx_realloc_lower()
343 struct ovl_fs *ofs = fc->s_fs_info; in ovl_add_layer()
344 struct ovl_config *config = &ofs->config; in ovl_add_layer()
345 struct ovl_fs_context *ctx = fc->fs_private; in ovl_add_layer()
349 case Opt_workdir: in ovl_add_layer()
350 swap(config->workdir, *pname); in ovl_add_layer()
351 swap(ctx->work, *path); in ovl_add_layer()
353 case Opt_upperdir: in ovl_add_layer()
354 swap(config->upperdir, *pname); in ovl_add_layer()
355 swap(ctx->upper, *path); in ovl_add_layer()
357 case Opt_datadir_add: in ovl_add_layer()
358 ctx->nr_data++; in ovl_add_layer()
360 case Opt_lowerdir: in ovl_add_layer()
362 case Opt_lowerdir_add: in ovl_add_layer()
363 WARN_ON(ctx->nr >= ctx->capacity); in ovl_add_layer()
364 l = &ctx->lower[ctx->nr++]; in ovl_add_layer()
366 swap(l->name, *pname); in ovl_add_layer()
367 swap(l->path, *path); in ovl_add_layer()
382 return -ENOMEM; in ovl_parse_layer()
413 struct ovl_fs_context_layer *l = ctx->lower; in ovl_reset_lowerdirs()
416 kfree(ctx->lowerdir_all); in ovl_reset_lowerdirs()
417 ctx->lowerdir_all = NULL; in ovl_reset_lowerdirs()
419 for (size_t nr = 0; nr < ctx->nr; nr++, l++) { in ovl_reset_lowerdirs()
420 path_put(&l->path); in ovl_reset_lowerdirs()
421 kfree(l->name); in ovl_reset_lowerdirs()
422 l->name = NULL; in ovl_reset_lowerdirs()
424 ctx->nr = 0; in ovl_reset_lowerdirs()
425 ctx->nr_data = 0; in ovl_reset_lowerdirs()
432 * Set "/lower1", "/lower2", and "/lower3" as lower layers and
433 * "/data1" and "/data2" as data lower layers. Any existing lower
439 struct ovl_fs_context *ctx = fc->fs_private; in ovl_parse_param_lowerdir()
449 /* drop all existing lower layers */ in ovl_parse_param_lowerdir()
456 pr_err("cannot append lower layer\n"); in ovl_parse_param_lowerdir()
457 return -EINVAL; in ovl_parse_param_lowerdir()
461 ctx->lowerdir_all = kstrdup(name, GFP_KERNEL); in ovl_parse_param_lowerdir()
462 if (!ctx->lowerdir_all) in ovl_parse_param_lowerdir()
463 return -ENOMEM; in ovl_parse_param_lowerdir()
467 return -ENOMEM; in ovl_parse_param_lowerdir()
469 err = -EINVAL; in ovl_parse_param_lowerdir()
475 pr_err("too many lower directories, limit is %d\n", OVL_MAX_STACK); in ovl_parse_param_lowerdir()
486 ctx->nr_data++; in ovl_parse_param_lowerdir()
489 if (ctx->nr == nr_lower) in ovl_parse_param_lowerdir()
492 err = -EINVAL; in ovl_parse_param_lowerdir()
499 if (ctx->nr_data > 0) { in ovl_parse_param_lowerdir()
500 pr_err("regular lower layers cannot follow data lower layers\n"); in ovl_parse_param_lowerdir()
508 /* This is a data lower layer. */ in ovl_parse_param_lowerdir()
526 struct ovl_fs *ofs = fc->s_fs_info; in ovl_parse_param()
527 struct ovl_config *config = &ofs->config; in ovl_parse_param()
528 struct ovl_fs_context *ctx = fc->fs_private; in ovl_parse_param()
531 if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { in ovl_parse_param()
537 if (fc->oldapi) in ovl_parse_param()
555 case Opt_lowerdir: in ovl_parse_param()
556 err = ovl_parse_param_lowerdir(param->string, fc); in ovl_parse_param()
558 case Opt_lowerdir_add: in ovl_parse_param()
559 case Opt_datadir_add: in ovl_parse_param()
560 case Opt_upperdir: in ovl_parse_param()
561 case Opt_workdir: in ovl_parse_param()
562 err = ovl_parse_layer(fc, param->string, opt); in ovl_parse_param()
564 case Opt_default_permissions: in ovl_parse_param()
565 config->default_permissions = true; in ovl_parse_param()
567 case Opt_redirect_dir: in ovl_parse_param()
568 config->redirect_mode = result.uint_32; in ovl_parse_param()
569 if (config->redirect_mode == OVL_REDIRECT_OFF) { in ovl_parse_param()
570 config->redirect_mode = ovl_redirect_always_follow ? in ovl_parse_param()
574 ctx->set.redirect = true; in ovl_parse_param()
576 case Opt_index: in ovl_parse_param()
577 config->index = result.uint_32; in ovl_parse_param()
578 ctx->set.index = true; in ovl_parse_param()
580 case Opt_uuid: in ovl_parse_param()
581 config->uuid = result.uint_32; in ovl_parse_param()
583 case Opt_nfs_export: in ovl_parse_param()
584 config->nfs_export = result.uint_32; in ovl_parse_param()
585 ctx->set.nfs_export = true; in ovl_parse_param()
587 case Opt_xino: in ovl_parse_param()
588 config->xino = result.uint_32; in ovl_parse_param()
590 case Opt_metacopy: in ovl_parse_param()
591 config->metacopy = result.uint_32; in ovl_parse_param()
592 ctx->set.metacopy = true; in ovl_parse_param()
594 case Opt_verity: in ovl_parse_param()
595 config->verity_mode = result.uint_32; in ovl_parse_param()
597 case Opt_volatile: in ovl_parse_param()
598 config->ovl_volatile = true; in ovl_parse_param()
600 case Opt_userxattr: in ovl_parse_param()
601 config->userxattr = true; in ovl_parse_param()
605 param->key); in ovl_parse_param()
606 return -EINVAL; in ovl_parse_param()
620 path_put(&ctx->upper); in ovl_fs_context_free()
621 path_put(&ctx->work); in ovl_fs_context_free()
622 kfree(ctx->lower); in ovl_fs_context_free()
628 struct ovl_fs *ofs = fc->s_fs_info; in ovl_free()
629 struct ovl_fs_context *ctx = fc->fs_private; in ovl_free()
646 struct super_block *sb = fc->root->d_sb; in ovl_reconfigure()
651 if (!(fc->sb_flags & SB_RDONLY) && ovl_force_readonly(ofs)) in ovl_reconfigure()
652 return -EROFS; in ovl_reconfigure()
654 if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb)) { in ovl_reconfigure()
655 upper_sb = ovl_upper_mnt(ofs)->mnt_sb; in ovl_reconfigure()
657 down_read(&upper_sb->s_umount); in ovl_reconfigure()
659 up_read(&upper_sb->s_umount); in ovl_reconfigure()
676 * the caller in fc->user_ns since we've raised FS_USERNS_MOUNT. We'll
688 return -ENOMEM; in ovl_init_fs_context()
691 * By default we allocate for three lower layers. It's likely in ovl_init_fs_context()
694 ctx->lower = kmalloc_array(3, sizeof(*ctx->lower), GFP_KERNEL_ACCOUNT); in ovl_init_fs_context()
695 if (!ctx->lower) in ovl_init_fs_context()
697 ctx->capacity = 3; in ovl_init_fs_context()
703 ofs->config.redirect_mode = ovl_redirect_mode_def(); in ovl_init_fs_context()
704 ofs->config.index = ovl_index_def; in ovl_init_fs_context()
705 ofs->config.uuid = ovl_uuid_def(); in ovl_init_fs_context()
706 ofs->config.nfs_export = ovl_nfs_export_def; in ovl_init_fs_context()
707 ofs->config.xino = ovl_xino_def(); in ovl_init_fs_context()
708 ofs->config.metacopy = ovl_metacopy_def; in ovl_init_fs_context()
710 fc->s_fs_info = ofs; in ovl_init_fs_context()
711 fc->fs_private = ctx; in ovl_init_fs_context()
712 fc->ops = &ovl_context_ops; in ovl_init_fs_context()
717 return -ENOMEM; in ovl_init_fs_context()
726 iput(ofs->workbasedir_trap); in ovl_free_fs()
727 iput(ofs->indexdir_trap); in ovl_free_fs()
728 iput(ofs->workdir_trap); in ovl_free_fs()
729 dput(ofs->whiteout); in ovl_free_fs()
730 dput(ofs->indexdir); in ovl_free_fs()
731 dput(ofs->workdir); in ovl_free_fs()
732 if (ofs->workdir_locked) in ovl_free_fs()
733 ovl_inuse_unlock(ofs->workbasedir); in ovl_free_fs()
734 dput(ofs->workbasedir); in ovl_free_fs()
735 if (ofs->upperdir_locked) in ovl_free_fs()
736 ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root); in ovl_free_fs()
738 /* Reuse ofs->config.lowerdirs as a vfsmount array before freeing it */ in ovl_free_fs()
739 mounts = (struct vfsmount **) ofs->config.lowerdirs; in ovl_free_fs()
740 for (i = 0; i < ofs->numlayer; i++) { in ovl_free_fs()
741 iput(ofs->layers[i].trap); in ovl_free_fs()
742 kfree(ofs->config.lowerdirs[i]); in ovl_free_fs()
743 mounts[i] = ofs->layers[i].mnt; in ovl_free_fs()
745 kern_unmount_array(mounts, ofs->numlayer); in ovl_free_fs()
746 kfree(ofs->layers); in ovl_free_fs()
747 for (i = 0; i < ofs->numfs; i++) in ovl_free_fs()
748 free_anon_bdev(ofs->fs[i].pseudo_dev); in ovl_free_fs()
749 kfree(ofs->fs); in ovl_free_fs()
751 kfree(ofs->config.lowerdirs); in ovl_free_fs()
752 kfree(ofs->config.upperdir); in ovl_free_fs()
753 kfree(ofs->config.workdir); in ovl_free_fs()
754 if (ofs->creator_cred) in ovl_free_fs()
755 put_cred(ofs->creator_cred); in ovl_free_fs()
762 struct ovl_opt_set set = ctx->set; in ovl_fs_params_verify()
764 /* Workdir/index are useless in non-upper mount */ in ovl_fs_params_verify()
765 if (!config->upperdir) { in ovl_fs_params_verify()
766 if (config->workdir) { in ovl_fs_params_verify()
767 pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n", in ovl_fs_params_verify()
768 config->workdir); in ovl_fs_params_verify()
769 kfree(config->workdir); in ovl_fs_params_verify()
770 config->workdir = NULL; in ovl_fs_params_verify()
772 if (config->index && set.index) { in ovl_fs_params_verify()
773 pr_info("option \"index=on\" is useless in a non-upper mount, ignore\n"); in ovl_fs_params_verify()
776 config->index = false; in ovl_fs_params_verify()
779 if (!config->upperdir && config->ovl_volatile) { in ovl_fs_params_verify()
780 pr_info("option \"volatile\" is meaningless in a non-upper mount, ignoring it.\n"); in ovl_fs_params_verify()
781 config->ovl_volatile = false; in ovl_fs_params_verify()
784 if (!config->upperdir && config->uuid == OVL_UUID_ON) { in ovl_fs_params_verify()
786 config->uuid = OVL_UUID_NULL; in ovl_fs_params_verify()
789 /* Resolve verity -> metacopy dependency */ in ovl_fs_params_verify()
790 if (config->verity_mode && !config->metacopy) { in ovl_fs_params_verify()
795 return -EINVAL; in ovl_fs_params_verify()
798 config->metacopy = true; in ovl_fs_params_verify()
805 if (!config->upperdir && config->redirect_mode == OVL_REDIRECT_FOLLOW) in ovl_fs_params_verify()
806 config->redirect_mode = OVL_REDIRECT_ON; in ovl_fs_params_verify()
808 /* Resolve verity -> metacopy -> redirect_dir dependency */ in ovl_fs_params_verify()
809 if (config->metacopy && config->redirect_mode != OVL_REDIRECT_ON) { in ovl_fs_params_verify()
813 return -EINVAL; in ovl_fs_params_verify()
815 if (config->verity_mode && set.redirect) { in ovl_fs_params_verify()
818 return -EINVAL; in ovl_fs_params_verify()
827 config->metacopy = false; in ovl_fs_params_verify()
830 config->redirect_mode = OVL_REDIRECT_ON; in ovl_fs_params_verify()
834 /* Resolve nfs_export -> index dependency */ in ovl_fs_params_verify()
835 if (config->nfs_export && !config->index) { in ovl_fs_params_verify()
836 if (!config->upperdir && in ovl_fs_params_verify()
837 config->redirect_mode != OVL_REDIRECT_NOFOLLOW) { in ovl_fs_params_verify()
838 …pr_info("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_exp… in ovl_fs_params_verify()
839 config->nfs_export = false; in ovl_fs_params_verify()
842 return -EINVAL; in ovl_fs_params_verify()
849 config->nfs_export = false; in ovl_fs_params_verify()
852 config->index = true; in ovl_fs_params_verify()
856 /* Resolve nfs_export -> !metacopy && !verity dependency */ in ovl_fs_params_verify()
857 if (config->nfs_export && config->metacopy) { in ovl_fs_params_verify()
860 return -EINVAL; in ovl_fs_params_verify()
868 config->nfs_export = false; in ovl_fs_params_verify()
869 } else if (config->verity_mode) { in ovl_fs_params_verify()
876 config->nfs_export = false; in ovl_fs_params_verify()
883 config->metacopy = false; in ovl_fs_params_verify()
888 /* Resolve userxattr -> !redirect && !metacopy && !verity dependency */ in ovl_fs_params_verify()
889 if (config->userxattr) { in ovl_fs_params_verify()
891 config->redirect_mode != OVL_REDIRECT_NOFOLLOW) { in ovl_fs_params_verify()
894 return -EINVAL; in ovl_fs_params_verify()
896 if (config->metacopy && set.metacopy) { in ovl_fs_params_verify()
898 return -EINVAL; in ovl_fs_params_verify()
900 if (config->verity_mode) { in ovl_fs_params_verify()
903 return -EINVAL; in ovl_fs_params_verify()
911 config->redirect_mode = OVL_REDIRECT_NOFOLLOW; in ovl_fs_params_verify()
912 config->metacopy = false; in ovl_fs_params_verify()
919 if (!config->userxattr && !capable(CAP_SYS_ADMIN)) { in ovl_fs_params_verify()
921 config->redirect_mode != OVL_REDIRECT_NOFOLLOW) { in ovl_fs_params_verify()
923 return -EPERM; in ovl_fs_params_verify()
925 if (config->metacopy && set.metacopy) { in ovl_fs_params_verify()
927 return -EPERM; in ovl_fs_params_verify()
929 if (config->verity_mode) { in ovl_fs_params_verify()
931 return -EPERM; in ovl_fs_params_verify()
933 if (ctx->nr_data > 0) { in ovl_fs_params_verify()
934 pr_err("lower data-only dirs require permission to access trusted xattrs\n"); in ovl_fs_params_verify()
935 return -EPERM; in ovl_fs_params_verify()
938 * Other xattr-dependent features should be disabled without in ovl_fs_params_verify()
943 if (ctx->nr_data > 0 && !config->metacopy) { in ovl_fs_params_verify()
944 pr_err("lower data-only dirs require metacopy support.\n"); in ovl_fs_params_verify()
945 return -EINVAL; in ovl_fs_params_verify()
961 struct super_block *sb = dentry->d_sb; in ovl_show_options()
964 char **lowerdirs = ofs->config.lowerdirs; in ovl_show_options()
977 nr_lower = ofs->numlayer; in ovl_show_options()
978 nr_merged_lower = nr_lower - ofs->numdatalayer; in ovl_show_options()
986 if (ofs->config.upperdir) { in ovl_show_options()
987 seq_show_option(m, "upperdir", ofs->config.upperdir); in ovl_show_options()
988 seq_show_option(m, "workdir", ofs->config.workdir); in ovl_show_options()
990 if (ofs->config.default_permissions) in ovl_show_options()
992 if (ofs->config.redirect_mode != ovl_redirect_mode_def()) in ovl_show_options()
994 ovl_redirect_mode(&ofs->config)); in ovl_show_options()
995 if (ofs->config.index != ovl_index_def) in ovl_show_options()
996 seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off"); in ovl_show_options()
997 if (ofs->config.uuid != ovl_uuid_def()) in ovl_show_options()
998 seq_printf(m, ",uuid=%s", ovl_uuid_mode(&ofs->config)); in ovl_show_options()
999 if (ofs->config.nfs_export != ovl_nfs_export_def) in ovl_show_options()
1000 seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ? in ovl_show_options()
1002 if (ofs->config.xino != ovl_xino_def() && !ovl_same_fs(ofs)) in ovl_show_options()
1003 seq_printf(m, ",xino=%s", ovl_xino_mode(&ofs->config)); in ovl_show_options()
1004 if (ofs->config.metacopy != ovl_metacopy_def) in ovl_show_options()
1006 ofs->config.metacopy ? "on" : "off"); in ovl_show_options()
1007 if (ofs->config.ovl_volatile) in ovl_show_options()
1009 if (ofs->config.userxattr) in ovl_show_options()
1011 if (ofs->config.verity_mode != ovl_verity_mode_def()) in ovl_show_options()
1013 ovl_verity_mode(&ofs->config)); in ovl_show_options()