diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-03-02 13:05:10 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-03-02 13:05:10 -0500 |
commit | 2833419a629d2d0eeb46f97c529f1057db7537b2 (patch) | |
tree | f628cf34dc2ba1edd8a6194a0e3ebfdfed1f7e08 /fs | |
parent | fb6d47a592678ad1f053d9584b4f7dc4095a5c53 (diff) | |
parent | 1c789249578895bb14ab62b4327306439b754857 (diff) |
Merge tag 'ceph-for-4.16-rc4' of git://github.com/ceph/ceph-client
Pull ceph fixes from Ilya Dryomov:
"A cap handling fix from Zhi that ensures that metadata writeback isn't
delayed and three error path memory leak fixups from Chengguang"
* tag 'ceph-for-4.16-rc4' of git://github.com/ceph/ceph-client:
ceph: fix potential memory leak in init_caches()
ceph: fix dentry leak when failing to init debugfs
libceph, ceph: avoid memory leak when specifying same option several times
ceph: flush dirty caps of unlinked inode ASAP
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ceph/caps.c | 26 | ||||
-rw-r--r-- | fs/ceph/dir.c | 28 | ||||
-rw-r--r-- | fs/ceph/super.c | 27 | ||||
-rw-r--r-- | fs/ceph/super.h | 2 |
4 files changed, 45 insertions, 38 deletions
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 6582c4507e6c..0e5bd3e3344e 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c | |||
@@ -3965,6 +3965,32 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode) | |||
3965 | } | 3965 | } |
3966 | 3966 | ||
3967 | /* | 3967 | /* |
3968 | * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it | ||
3969 | * looks like the link count will hit 0, drop any other caps (other | ||
3970 | * than PIN) we don't specifically want (due to the file still being | ||
3971 | * open). | ||
3972 | */ | ||
3973 | int ceph_drop_caps_for_unlink(struct inode *inode) | ||
3974 | { | ||
3975 | struct ceph_inode_info *ci = ceph_inode(inode); | ||
3976 | int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; | ||
3977 | |||
3978 | spin_lock(&ci->i_ceph_lock); | ||
3979 | if (inode->i_nlink == 1) { | ||
3980 | drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN); | ||
3981 | |||
3982 | ci->i_ceph_flags |= CEPH_I_NODELAY; | ||
3983 | if (__ceph_caps_dirty(ci)) { | ||
3984 | struct ceph_mds_client *mdsc = | ||
3985 | ceph_inode_to_client(inode)->mdsc; | ||
3986 | __cap_delay_requeue_front(mdsc, ci); | ||
3987 | } | ||
3988 | } | ||
3989 | spin_unlock(&ci->i_ceph_lock); | ||
3990 | return drop; | ||
3991 | } | ||
3992 | |||
3993 | /* | ||
3968 | * Helpers for embedding cap and dentry lease releases into mds | 3994 | * Helpers for embedding cap and dentry lease releases into mds |
3969 | * requests. | 3995 | * requests. |
3970 | * | 3996 | * |
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 0c4346806e17..f1d9c6cc0491 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c | |||
@@ -1003,26 +1003,6 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir, | |||
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | /* | 1005 | /* |
1006 | * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it | ||
1007 | * looks like the link count will hit 0, drop any other caps (other | ||
1008 | * than PIN) we don't specifically want (due to the file still being | ||
1009 | * open). | ||
1010 | */ | ||
1011 | static int drop_caps_for_unlink(struct inode *inode) | ||
1012 | { | ||
1013 | struct ceph_inode_info *ci = ceph_inode(inode); | ||
1014 | int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; | ||
1015 | |||
1016 | spin_lock(&ci->i_ceph_lock); | ||
1017 | if (inode->i_nlink == 1) { | ||
1018 | drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN); | ||
1019 | ci->i_ceph_flags |= CEPH_I_NODELAY; | ||
1020 | } | ||
1021 | spin_unlock(&ci->i_ceph_lock); | ||
1022 | return drop; | ||
1023 | } | ||
1024 | |||
1025 | /* | ||
1026 | * rmdir and unlink are differ only by the metadata op code | 1006 | * rmdir and unlink are differ only by the metadata op code |
1027 | */ | 1007 | */ |
1028 | static int ceph_unlink(struct inode *dir, struct dentry *dentry) | 1008 | static int ceph_unlink(struct inode *dir, struct dentry *dentry) |
@@ -1056,7 +1036,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry) | |||
1056 | set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); | 1036 | set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); |
1057 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; | 1037 | req->r_dentry_drop = CEPH_CAP_FILE_SHARED; |
1058 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; | 1038 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
1059 | req->r_inode_drop = drop_caps_for_unlink(inode); | 1039 | req->r_inode_drop = ceph_drop_caps_for_unlink(inode); |
1060 | err = ceph_mdsc_do_request(mdsc, dir, req); | 1040 | err = ceph_mdsc_do_request(mdsc, dir, req); |
1061 | if (!err && !req->r_reply_info.head->is_dentry) | 1041 | if (!err && !req->r_reply_info.head->is_dentry) |
1062 | d_delete(dentry); | 1042 | d_delete(dentry); |
@@ -1104,8 +1084,10 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
1104 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; | 1084 | req->r_dentry_unless = CEPH_CAP_FILE_EXCL; |
1105 | /* release LINK_RDCACHE on source inode (mds will lock it) */ | 1085 | /* release LINK_RDCACHE on source inode (mds will lock it) */ |
1106 | req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; | 1086 | req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; |
1107 | if (d_really_is_positive(new_dentry)) | 1087 | if (d_really_is_positive(new_dentry)) { |
1108 | req->r_inode_drop = drop_caps_for_unlink(d_inode(new_dentry)); | 1088 | req->r_inode_drop = |
1089 | ceph_drop_caps_for_unlink(d_inode(new_dentry)); | ||
1090 | } | ||
1109 | err = ceph_mdsc_do_request(mdsc, old_dir, req); | 1091 | err = ceph_mdsc_do_request(mdsc, old_dir, req); |
1110 | if (!err && !req->r_reply_info.head->is_dentry) { | 1092 | if (!err && !req->r_reply_info.head->is_dentry) { |
1111 | /* | 1093 | /* |
diff --git a/fs/ceph/super.c b/fs/ceph/super.c index a62d2a9841dc..fb2bc9c15a23 100644 --- a/fs/ceph/super.c +++ b/fs/ceph/super.c | |||
@@ -225,6 +225,7 @@ static int parse_fsopt_token(char *c, void *private) | |||
225 | return -ENOMEM; | 225 | return -ENOMEM; |
226 | break; | 226 | break; |
227 | case Opt_mds_namespace: | 227 | case Opt_mds_namespace: |
228 | kfree(fsopt->mds_namespace); | ||
228 | fsopt->mds_namespace = kstrndup(argstr[0].from, | 229 | fsopt->mds_namespace = kstrndup(argstr[0].from, |
229 | argstr[0].to-argstr[0].from, | 230 | argstr[0].to-argstr[0].from, |
230 | GFP_KERNEL); | 231 | GFP_KERNEL); |
@@ -232,6 +233,7 @@ static int parse_fsopt_token(char *c, void *private) | |||
232 | return -ENOMEM; | 233 | return -ENOMEM; |
233 | break; | 234 | break; |
234 | case Opt_fscache_uniq: | 235 | case Opt_fscache_uniq: |
236 | kfree(fsopt->fscache_uniq); | ||
235 | fsopt->fscache_uniq = kstrndup(argstr[0].from, | 237 | fsopt->fscache_uniq = kstrndup(argstr[0].from, |
236 | argstr[0].to-argstr[0].from, | 238 | argstr[0].to-argstr[0].from, |
237 | GFP_KERNEL); | 239 | GFP_KERNEL); |
@@ -711,14 +713,17 @@ static int __init init_caches(void) | |||
711 | goto bad_dentry; | 713 | goto bad_dentry; |
712 | 714 | ||
713 | ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); | 715 | ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); |
714 | |||
715 | if (!ceph_file_cachep) | 716 | if (!ceph_file_cachep) |
716 | goto bad_file; | 717 | goto bad_file; |
717 | 718 | ||
718 | if ((error = ceph_fscache_register())) | 719 | error = ceph_fscache_register(); |
719 | goto bad_file; | 720 | if (error) |
721 | goto bad_fscache; | ||
720 | 722 | ||
721 | return 0; | 723 | return 0; |
724 | |||
725 | bad_fscache: | ||
726 | kmem_cache_destroy(ceph_file_cachep); | ||
722 | bad_file: | 727 | bad_file: |
723 | kmem_cache_destroy(ceph_dentry_cachep); | 728 | kmem_cache_destroy(ceph_dentry_cachep); |
724 | bad_dentry: | 729 | bad_dentry: |
@@ -836,7 +841,6 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc) | |||
836 | int err; | 841 | int err; |
837 | unsigned long started = jiffies; /* note the start time */ | 842 | unsigned long started = jiffies; /* note the start time */ |
838 | struct dentry *root; | 843 | struct dentry *root; |
839 | int first = 0; /* first vfsmount for this super_block */ | ||
840 | 844 | ||
841 | dout("mount start %p\n", fsc); | 845 | dout("mount start %p\n", fsc); |
842 | mutex_lock(&fsc->client->mount_mutex); | 846 | mutex_lock(&fsc->client->mount_mutex); |
@@ -861,17 +865,17 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc) | |||
861 | path = fsc->mount_options->server_path + 1; | 865 | path = fsc->mount_options->server_path + 1; |
862 | dout("mount opening path %s\n", path); | 866 | dout("mount opening path %s\n", path); |
863 | } | 867 | } |
868 | |||
869 | err = ceph_fs_debugfs_init(fsc); | ||
870 | if (err < 0) | ||
871 | goto out; | ||
872 | |||
864 | root = open_root_dentry(fsc, path, started); | 873 | root = open_root_dentry(fsc, path, started); |
865 | if (IS_ERR(root)) { | 874 | if (IS_ERR(root)) { |
866 | err = PTR_ERR(root); | 875 | err = PTR_ERR(root); |
867 | goto out; | 876 | goto out; |
868 | } | 877 | } |
869 | fsc->sb->s_root = dget(root); | 878 | fsc->sb->s_root = dget(root); |
870 | first = 1; | ||
871 | |||
872 | err = ceph_fs_debugfs_init(fsc); | ||
873 | if (err < 0) | ||
874 | goto fail; | ||
875 | } else { | 879 | } else { |
876 | root = dget(fsc->sb->s_root); | 880 | root = dget(fsc->sb->s_root); |
877 | } | 881 | } |
@@ -881,11 +885,6 @@ static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc) | |||
881 | mutex_unlock(&fsc->client->mount_mutex); | 885 | mutex_unlock(&fsc->client->mount_mutex); |
882 | return root; | 886 | return root; |
883 | 887 | ||
884 | fail: | ||
885 | if (first) { | ||
886 | dput(fsc->sb->s_root); | ||
887 | fsc->sb->s_root = NULL; | ||
888 | } | ||
889 | out: | 888 | out: |
890 | mutex_unlock(&fsc->client->mount_mutex); | 889 | mutex_unlock(&fsc->client->mount_mutex); |
891 | return ERR_PTR(err); | 890 | return ERR_PTR(err); |
diff --git a/fs/ceph/super.h b/fs/ceph/super.h index 21b2e5b004eb..1c2086e0fec2 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h | |||
@@ -987,7 +987,7 @@ extern void ceph_check_caps(struct ceph_inode_info *ci, int flags, | |||
987 | struct ceph_mds_session *session); | 987 | struct ceph_mds_session *session); |
988 | extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc); | 988 | extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc); |
989 | extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc); | 989 | extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc); |
990 | 990 | extern int ceph_drop_caps_for_unlink(struct inode *inode); | |
991 | extern int ceph_encode_inode_release(void **p, struct inode *inode, | 991 | extern int ceph_encode_inode_release(void **p, struct inode *inode, |
992 | int mds, int drop, int unless, int force); | 992 | int mds, int drop, int unless, int force); |
993 | extern int ceph_encode_dentry_release(void **p, struct dentry *dn, | 993 | extern int ceph_encode_dentry_release(void **p, struct dentry *dn, |