diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2014-12-12 18:59:48 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2014-12-12 18:59:48 -0500 |
commit | 3b7a9a249a93e68b7bb318de40e64d3b68ba1a6d (patch) | |
tree | 3eccbb92cdef99b3301eeb82091428fa451c8567 /fs | |
parent | 4ebc581828d5d0fe189ca06cef8b7a63cb4583d5 (diff) |
ovl: mount: change order of initialization
Move allocation of root entry above to where it's needed.
Move initializations related to upperdir and workdir near each other.
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/overlayfs/super.c | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index cc7a0f3aa0dd..a17702833dd0 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c | |||
@@ -723,7 +723,6 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
723 | struct path lowerpath; | 723 | struct path lowerpath; |
724 | struct path upperpath; | 724 | struct path upperpath; |
725 | struct path workpath; | 725 | struct path workpath; |
726 | struct inode *root_inode; | ||
727 | struct dentry *root_dentry; | 726 | struct dentry *root_dentry; |
728 | struct ovl_entry *oe; | 727 | struct ovl_entry *oe; |
729 | struct ovl_fs *ufs; | 728 | struct ovl_fs *ufs; |
@@ -749,54 +748,49 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
749 | goto out_free_config; | 748 | goto out_free_config; |
750 | } | 749 | } |
751 | 750 | ||
752 | err = -ENOMEM; | ||
753 | oe = ovl_alloc_entry(1); | ||
754 | if (oe == NULL) | ||
755 | goto out_free_config; | ||
756 | |||
757 | err = ovl_mount_dir(ufs->config.upperdir, &upperpath); | 751 | err = ovl_mount_dir(ufs->config.upperdir, &upperpath); |
758 | if (err) | 752 | if (err) |
759 | goto out_free_oe; | 753 | goto out_free_config; |
760 | 754 | ||
761 | err = ovl_mount_dir(ufs->config.lowerdir, &lowerpath); | 755 | err = ovl_mount_dir(ufs->config.workdir, &workpath); |
762 | if (err) | 756 | if (err) |
763 | goto out_put_upperpath; | 757 | goto out_put_upperpath; |
764 | 758 | ||
765 | err = ovl_mount_dir(ufs->config.workdir, &workpath); | 759 | err = ovl_mount_dir(ufs->config.lowerdir, &lowerpath); |
766 | if (err) | 760 | if (err) |
767 | goto out_put_lowerpath; | 761 | goto out_put_workpath; |
768 | 762 | ||
769 | err = -EINVAL; | 763 | err = -EINVAL; |
770 | if (!S_ISDIR(upperpath.dentry->d_inode->i_mode) || | 764 | if (!S_ISDIR(upperpath.dentry->d_inode->i_mode) || |
771 | !S_ISDIR(lowerpath.dentry->d_inode->i_mode) || | 765 | !S_ISDIR(lowerpath.dentry->d_inode->i_mode) || |
772 | !S_ISDIR(workpath.dentry->d_inode->i_mode)) { | 766 | !S_ISDIR(workpath.dentry->d_inode->i_mode)) { |
773 | pr_err("overlayfs: upperdir or lowerdir or workdir not a directory\n"); | 767 | pr_err("overlayfs: upperdir or lowerdir or workdir not a directory\n"); |
774 | goto out_put_workpath; | 768 | goto out_put_lowerpath; |
775 | } | 769 | } |
776 | 770 | ||
777 | if (upperpath.mnt != workpath.mnt) { | 771 | if (upperpath.mnt != workpath.mnt) { |
778 | pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); | 772 | pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); |
779 | goto out_put_workpath; | 773 | goto out_put_lowerpath; |
780 | } | 774 | } |
781 | if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) { | 775 | if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) { |
782 | pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); | 776 | pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); |
783 | goto out_put_workpath; | 777 | goto out_put_lowerpath; |
784 | } | 778 | } |
785 | 779 | ||
786 | if (!ovl_is_allowed_fs_type(upperpath.dentry)) { | 780 | if (!ovl_is_allowed_fs_type(upperpath.dentry)) { |
787 | pr_err("overlayfs: filesystem of upperdir is not supported\n"); | 781 | pr_err("overlayfs: filesystem of upperdir is not supported\n"); |
788 | goto out_put_workpath; | 782 | goto out_put_lowerpath; |
789 | } | 783 | } |
790 | 784 | ||
791 | if (!ovl_is_allowed_fs_type(lowerpath.dentry)) { | 785 | if (!ovl_is_allowed_fs_type(lowerpath.dentry)) { |
792 | pr_err("overlayfs: filesystem of lowerdir is not supported\n"); | 786 | pr_err("overlayfs: filesystem of lowerdir is not supported\n"); |
793 | goto out_put_workpath; | 787 | goto out_put_lowerpath; |
794 | } | 788 | } |
795 | 789 | ||
796 | err = vfs_statfs(&lowerpath, &statfs); | 790 | err = vfs_statfs(&lowerpath, &statfs); |
797 | if (err) { | 791 | if (err) { |
798 | pr_err("overlayfs: statfs failed on lowerpath\n"); | 792 | pr_err("overlayfs: statfs failed on lowerpath\n"); |
799 | goto out_put_workpath; | 793 | goto out_put_lowerpath; |
800 | } | 794 | } |
801 | ufs->lower_namelen = statfs.f_namelen; | 795 | ufs->lower_namelen = statfs.f_namelen; |
802 | 796 | ||
@@ -806,19 +800,27 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
806 | err = -EINVAL; | 800 | err = -EINVAL; |
807 | if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { | 801 | if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { |
808 | pr_err("overlayfs: maximum fs stacking depth exceeded\n"); | 802 | pr_err("overlayfs: maximum fs stacking depth exceeded\n"); |
809 | goto out_put_workpath; | 803 | goto out_put_lowerpath; |
810 | } | 804 | } |
811 | 805 | ||
812 | ufs->upper_mnt = clone_private_mount(&upperpath); | 806 | ufs->upper_mnt = clone_private_mount(&upperpath); |
813 | err = PTR_ERR(ufs->upper_mnt); | 807 | err = PTR_ERR(ufs->upper_mnt); |
814 | if (IS_ERR(ufs->upper_mnt)) { | 808 | if (IS_ERR(ufs->upper_mnt)) { |
815 | pr_err("overlayfs: failed to clone upperpath\n"); | 809 | pr_err("overlayfs: failed to clone upperpath\n"); |
816 | goto out_put_workpath; | 810 | goto out_put_lowerpath; |
811 | } | ||
812 | |||
813 | ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry); | ||
814 | err = PTR_ERR(ufs->workdir); | ||
815 | if (IS_ERR(ufs->workdir)) { | ||
816 | pr_err("overlayfs: failed to create directory %s/%s\n", | ||
817 | ufs->config.workdir, OVL_WORKDIR_NAME); | ||
818 | goto out_put_upper_mnt; | ||
817 | } | 819 | } |
818 | 820 | ||
819 | ufs->lower_mnt = kcalloc(1, sizeof(struct vfsmount *), GFP_KERNEL); | 821 | ufs->lower_mnt = kcalloc(1, sizeof(struct vfsmount *), GFP_KERNEL); |
820 | if (ufs->lower_mnt == NULL) | 822 | if (ufs->lower_mnt == NULL) |
821 | goto out_put_upper_mnt; | 823 | goto out_put_workdir; |
822 | 824 | ||
823 | mnt = clone_private_mount(&lowerpath); | 825 | mnt = clone_private_mount(&lowerpath); |
824 | err = PTR_ERR(mnt); | 826 | err = PTR_ERR(mnt); |
@@ -835,14 +837,6 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
835 | ufs->lower_mnt[0] = mnt; | 837 | ufs->lower_mnt[0] = mnt; |
836 | ufs->numlower = 1; | 838 | ufs->numlower = 1; |
837 | 839 | ||
838 | ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry); | ||
839 | err = PTR_ERR(ufs->workdir); | ||
840 | if (IS_ERR(ufs->workdir)) { | ||
841 | pr_err("overlayfs: failed to create directory %s/%s\n", | ||
842 | ufs->config.workdir, OVL_WORKDIR_NAME); | ||
843 | goto out_put_lower_mnt; | ||
844 | } | ||
845 | |||
846 | /* If the upper fs is r/o, we mark overlayfs r/o too */ | 840 | /* If the upper fs is r/o, we mark overlayfs r/o too */ |
847 | if (ufs->upper_mnt->mnt_sb->s_flags & MS_RDONLY) | 841 | if (ufs->upper_mnt->mnt_sb->s_flags & MS_RDONLY) |
848 | sb->s_flags |= MS_RDONLY; | 842 | sb->s_flags |= MS_RDONLY; |
@@ -850,13 +844,13 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
850 | sb->s_d_op = &ovl_dentry_operations; | 844 | sb->s_d_op = &ovl_dentry_operations; |
851 | 845 | ||
852 | err = -ENOMEM; | 846 | err = -ENOMEM; |
853 | root_inode = ovl_new_inode(sb, S_IFDIR, oe); | 847 | oe = ovl_alloc_entry(1); |
854 | if (!root_inode) | 848 | if (!oe) |
855 | goto out_put_workdir; | 849 | goto out_put_lower_mnt; |
856 | 850 | ||
857 | root_dentry = d_make_root(root_inode); | 851 | root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, oe)); |
858 | if (!root_dentry) | 852 | if (!root_dentry) |
859 | goto out_put_workdir; | 853 | goto out_free_oe; |
860 | 854 | ||
861 | mntput(upperpath.mnt); | 855 | mntput(upperpath.mnt); |
862 | mntput(lowerpath.mnt); | 856 | mntput(lowerpath.mnt); |
@@ -875,22 +869,22 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) | |||
875 | 869 | ||
876 | return 0; | 870 | return 0; |
877 | 871 | ||
878 | out_put_workdir: | 872 | out_free_oe: |
879 | dput(ufs->workdir); | 873 | kfree(oe); |
880 | out_put_lower_mnt: | 874 | out_put_lower_mnt: |
881 | for (i = 0; i < ufs->numlower; i++) | 875 | for (i = 0; i < ufs->numlower; i++) |
882 | mntput(ufs->lower_mnt[i]); | 876 | mntput(ufs->lower_mnt[i]); |
883 | kfree(ufs->lower_mnt); | 877 | kfree(ufs->lower_mnt); |
878 | out_put_workdir: | ||
879 | dput(ufs->workdir); | ||
884 | out_put_upper_mnt: | 880 | out_put_upper_mnt: |
885 | mntput(ufs->upper_mnt); | 881 | mntput(ufs->upper_mnt); |
886 | out_put_workpath: | ||
887 | path_put(&workpath); | ||
888 | out_put_lowerpath: | 882 | out_put_lowerpath: |
889 | path_put(&lowerpath); | 883 | path_put(&lowerpath); |
884 | out_put_workpath: | ||
885 | path_put(&workpath); | ||
890 | out_put_upperpath: | 886 | out_put_upperpath: |
891 | path_put(&upperpath); | 887 | path_put(&upperpath); |
892 | out_free_oe: | ||
893 | kfree(oe); | ||
894 | out_free_config: | 888 | out_free_config: |
895 | kfree(ufs->config.lowerdir); | 889 | kfree(ufs->config.lowerdir); |
896 | kfree(ufs->config.upperdir); | 890 | kfree(ufs->config.upperdir); |