Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 2 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 3 | #include <linux/ceph/ceph_debug.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 4 | |
| 5 | #include <linux/backing-dev.h> |
Sage Weil | c309f0a | 2010-06-30 21:34:01 -0700 | [diff] [blame] | 6 | #include <linux/ctype.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 7 | #include <linux/fs.h> |
| 8 | #include <linux/inet.h> |
| 9 | #include <linux/in6.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/mount.h> |
| 12 | #include <linux/parser.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 13 | #include <linux/sched.h> |
| 14 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 16 | #include <linux/statfs.h> |
| 17 | #include <linux/string.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 18 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 19 | #include "super.h" |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 20 | #include "mds_client.h" |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 21 | #include "cache.h" |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 22 | |
Sage Weil | 1fe60e5 | 2012-07-30 16:23:22 -0700 | [diff] [blame] | 23 | #include <linux/ceph/ceph_features.h> |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 24 | #include <linux/ceph/decode.h> |
| 25 | #include <linux/ceph/mon_client.h> |
| 26 | #include <linux/ceph/auth.h> |
| 27 | #include <linux/ceph/debugfs.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Ceph superblock operations |
| 31 | * |
| 32 | * Handle the basics of mounting, unmounting. |
| 33 | */ |
| 34 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 35 | /* |
| 36 | * super ops |
| 37 | */ |
| 38 | static void ceph_put_super(struct super_block *s) |
| 39 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 40 | struct ceph_fs_client *fsc = ceph_sb_to_client(s); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 41 | |
| 42 | dout("put_super\n"); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 43 | ceph_mdsc_close_sessions(fsc->mdsc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 47 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 48 | struct ceph_fs_client *fsc = ceph_inode_to_client(d_inode(dentry)); |
Luis Henriques | 73fb094 | 2018-05-28 18:37:40 +0100 | [diff] [blame] | 49 | struct ceph_mon_client *monc = &fsc->client->monc; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 50 | struct ceph_statfs st; |
| 51 | u64 fsid; |
| 52 | int err; |
Douglas Fuller | 06d7437 | 2017-08-16 10:19:27 -0400 | [diff] [blame] | 53 | u64 data_pool; |
| 54 | |
| 55 | if (fsc->mdsc->mdsmap->m_num_data_pg_pools == 1) { |
| 56 | data_pool = fsc->mdsc->mdsmap->m_data_pg_pools[0]; |
| 57 | } else { |
| 58 | data_pool = CEPH_NOPOOL; |
| 59 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 60 | |
| 61 | dout("statfs\n"); |
Luis Henriques | 73fb094 | 2018-05-28 18:37:40 +0100 | [diff] [blame] | 62 | err = ceph_monc_do_statfs(monc, data_pool, &st); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 63 | if (err < 0) |
| 64 | return err; |
| 65 | |
| 66 | /* fill in kstatfs */ |
| 67 | buf->f_type = CEPH_SUPER_MAGIC; /* ?? */ |
| 68 | |
| 69 | /* |
| 70 | * express utilization in terms of large blocks to avoid |
| 71 | * overflow on 32-bit machines. |
Sage Weil | 92a49fb | 2013-02-22 15:31:00 -0800 | [diff] [blame] | 72 | * |
| 73 | * NOTE: for the time being, we make bsize == frsize to humor |
| 74 | * not-yet-ancient versions of glibc that are broken. |
| 75 | * Someday, we will probably want to report a real block |
| 76 | * size... whatever that may mean for a network file system! |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 77 | */ |
| 78 | buf->f_bsize = 1 << CEPH_BLOCK_SHIFT; |
Sage Weil | 92a49fb | 2013-02-22 15:31:00 -0800 | [diff] [blame] | 79 | buf->f_frsize = 1 << CEPH_BLOCK_SHIFT; |
Luis Henriques | 9122eed | 2018-01-31 10:53:13 +0000 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * By default use root quota for stats; fallback to overall filesystem |
| 83 | * usage if using 'noquotadf' mount option or if the root dir doesn't |
| 84 | * have max_bytes quota set. |
| 85 | */ |
| 86 | if (ceph_test_mount_opt(fsc, NOQUOTADF) || |
| 87 | !ceph_quota_update_statfs(fsc, buf)) { |
| 88 | buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10); |
| 89 | buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10); |
| 90 | buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10); |
| 91 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 92 | |
| 93 | buf->f_files = le64_to_cpu(st.num_objects); |
| 94 | buf->f_ffree = -1; |
Sage Weil | 558d349 | 2010-06-01 12:51:12 -0700 | [diff] [blame] | 95 | buf->f_namelen = NAME_MAX; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 96 | |
Jeff Layton | 080a330 | 2017-10-23 10:58:40 -0400 | [diff] [blame] | 97 | /* Must convert the fsid, for consistent values across arches */ |
Luis Henriques | 73fb094 | 2018-05-28 18:37:40 +0100 | [diff] [blame] | 98 | mutex_lock(&monc->mutex); |
| 99 | fsid = le64_to_cpu(*(__le64 *)(&monc->monmap->fsid)) ^ |
| 100 | le64_to_cpu(*((__le64 *)&monc->monmap->fsid + 1)); |
| 101 | mutex_unlock(&monc->mutex); |
| 102 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 103 | buf->f_fsid.val[0] = fsid & 0xffffffff; |
| 104 | buf->f_fsid.val[1] = fsid >> 32; |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | |
Sage Weil | 2d9c98a | 2010-07-30 09:38:13 -0700 | [diff] [blame] | 110 | static int ceph_sync_fs(struct super_block *sb, int wait) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 111 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 112 | struct ceph_fs_client *fsc = ceph_sb_to_client(sb); |
Sage Weil | 2d9c98a | 2010-07-30 09:38:13 -0700 | [diff] [blame] | 113 | |
| 114 | if (!wait) { |
| 115 | dout("sync_fs (non-blocking)\n"); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 116 | ceph_flush_dirty_caps(fsc->mdsc); |
Sage Weil | 2d9c98a | 2010-07-30 09:38:13 -0700 | [diff] [blame] | 117 | dout("sync_fs (non-blocking) done\n"); |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | dout("sync_fs (blocking)\n"); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 122 | ceph_osdc_sync(&fsc->client->osdc); |
| 123 | ceph_mdsc_sync(fsc->mdsc); |
Sage Weil | 2d9c98a | 2010-07-30 09:38:13 -0700 | [diff] [blame] | 124 | dout("sync_fs (blocking) done\n"); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 128 | /* |
| 129 | * mount options |
| 130 | */ |
| 131 | enum { |
| 132 | Opt_wsize, |
| 133 | Opt_rsize, |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 134 | Opt_rasize, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 135 | Opt_caps_wanted_delay_min, |
| 136 | Opt_caps_wanted_delay_max, |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 137 | Opt_caps_max, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 138 | Opt_readdir_max_entries, |
| 139 | Opt_readdir_max_bytes, |
| 140 | Opt_congestion_kb, |
| 141 | Opt_last_int, |
| 142 | /* int args above */ |
| 143 | Opt_snapdirname, |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 144 | Opt_mds_namespace, |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 145 | Opt_fscache_uniq, |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 146 | Opt_recover_session, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 147 | Opt_last_string, |
| 148 | /* string args above */ |
| 149 | Opt_dirstat, |
| 150 | Opt_nodirstat, |
| 151 | Opt_rbytes, |
| 152 | Opt_norbytes, |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 153 | Opt_asyncreaddir, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 154 | Opt_noasyncreaddir, |
Sage Weil | a40dc6c | 2012-01-10 09:12:55 -0800 | [diff] [blame] | 155 | Opt_dcache, |
| 156 | Opt_nodcache, |
Yehuda Sadeh | ad1fee9 | 2011-01-21 16:44:03 -0800 | [diff] [blame] | 157 | Opt_ino32, |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 158 | Opt_noino32, |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 159 | Opt_fscache, |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 160 | Opt_nofscache, |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 161 | Opt_poolperm, |
| 162 | Opt_nopoolperm, |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 163 | Opt_require_active_mds, |
| 164 | Opt_norequire_active_mds, |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 165 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
| 166 | Opt_acl, |
| 167 | #endif |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 168 | Opt_noacl, |
Luis Henriques | 9122eed | 2018-01-31 10:53:13 +0000 | [diff] [blame] | 169 | Opt_quotadf, |
| 170 | Opt_noquotadf, |
Luis Henriques | ea4cdc5 | 2018-10-15 16:46:00 +0100 | [diff] [blame] | 171 | Opt_copyfrom, |
| 172 | Opt_nocopyfrom, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | static match_table_t fsopt_tokens = { |
| 176 | {Opt_wsize, "wsize=%d"}, |
| 177 | {Opt_rsize, "rsize=%d"}, |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 178 | {Opt_rasize, "rasize=%d"}, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 179 | {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"}, |
| 180 | {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"}, |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 181 | {Opt_caps_max, "caps_max=%d"}, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 182 | {Opt_readdir_max_entries, "readdir_max_entries=%d"}, |
| 183 | {Opt_readdir_max_bytes, "readdir_max_bytes=%d"}, |
| 184 | {Opt_congestion_kb, "write_congestion_kb=%d"}, |
| 185 | /* int args above */ |
| 186 | {Opt_snapdirname, "snapdirname=%s"}, |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 187 | {Opt_mds_namespace, "mds_namespace=%s"}, |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 188 | {Opt_recover_session, "recover_session=%s"}, |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 189 | {Opt_fscache_uniq, "fsc=%s"}, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 190 | /* string args above */ |
| 191 | {Opt_dirstat, "dirstat"}, |
| 192 | {Opt_nodirstat, "nodirstat"}, |
| 193 | {Opt_rbytes, "rbytes"}, |
| 194 | {Opt_norbytes, "norbytes"}, |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 195 | {Opt_asyncreaddir, "asyncreaddir"}, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 196 | {Opt_noasyncreaddir, "noasyncreaddir"}, |
Sage Weil | a40dc6c | 2012-01-10 09:12:55 -0800 | [diff] [blame] | 197 | {Opt_dcache, "dcache"}, |
| 198 | {Opt_nodcache, "nodcache"}, |
Yehuda Sadeh | ad1fee9 | 2011-01-21 16:44:03 -0800 | [diff] [blame] | 199 | {Opt_ino32, "ino32"}, |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 200 | {Opt_noino32, "noino32"}, |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 201 | {Opt_fscache, "fsc"}, |
| 202 | {Opt_nofscache, "nofsc"}, |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 203 | {Opt_poolperm, "poolperm"}, |
| 204 | {Opt_nopoolperm, "nopoolperm"}, |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 205 | {Opt_require_active_mds, "require_active_mds"}, |
| 206 | {Opt_norequire_active_mds, "norequire_active_mds"}, |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 207 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
| 208 | {Opt_acl, "acl"}, |
| 209 | #endif |
| 210 | {Opt_noacl, "noacl"}, |
Luis Henriques | 9122eed | 2018-01-31 10:53:13 +0000 | [diff] [blame] | 211 | {Opt_quotadf, "quotadf"}, |
| 212 | {Opt_noquotadf, "noquotadf"}, |
Luis Henriques | ea4cdc5 | 2018-10-15 16:46:00 +0100 | [diff] [blame] | 213 | {Opt_copyfrom, "copyfrom"}, |
| 214 | {Opt_nocopyfrom, "nocopyfrom"}, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 215 | {-1, NULL} |
| 216 | }; |
| 217 | |
| 218 | static int parse_fsopt_token(char *c, void *private) |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 219 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 220 | struct ceph_mount_options *fsopt = private; |
| 221 | substring_t argstr[MAX_OPT_ARGS]; |
| 222 | int token, intval, ret; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 223 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 224 | token = match_token((char *)c, fsopt_tokens, argstr); |
| 225 | if (token < 0) |
| 226 | return -EINVAL; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 227 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 228 | if (token < Opt_last_int) { |
| 229 | ret = match_int(&argstr[0], &intval); |
| 230 | if (ret < 0) { |
Ilya Dryomov | 2f56b6b | 2018-06-27 16:38:13 +0200 | [diff] [blame] | 231 | pr_err("bad option arg (not int) at '%s'\n", c); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 232 | return ret; |
| 233 | } |
| 234 | dout("got int token %d val %d\n", token, intval); |
| 235 | } else if (token > Opt_last_int && token < Opt_last_string) { |
| 236 | dout("got string token %d val %s\n", token, |
| 237 | argstr[0].from); |
| 238 | } else { |
| 239 | dout("got token %d\n", token); |
| 240 | } |
| 241 | |
| 242 | switch (token) { |
| 243 | case Opt_snapdirname: |
| 244 | kfree(fsopt->snapdir_name); |
| 245 | fsopt->snapdir_name = kstrndup(argstr[0].from, |
| 246 | argstr[0].to-argstr[0].from, |
| 247 | GFP_KERNEL); |
| 248 | if (!fsopt->snapdir_name) |
| 249 | return -ENOMEM; |
| 250 | break; |
Yan, Zheng | 235a098 | 2016-03-30 17:18:34 +0800 | [diff] [blame] | 251 | case Opt_mds_namespace: |
Chengguang Xu | 937441f | 2018-02-06 08:25:55 +0800 | [diff] [blame] | 252 | kfree(fsopt->mds_namespace); |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 253 | fsopt->mds_namespace = kstrndup(argstr[0].from, |
| 254 | argstr[0].to-argstr[0].from, |
| 255 | GFP_KERNEL); |
| 256 | if (!fsopt->mds_namespace) |
| 257 | return -ENOMEM; |
Yan, Zheng | 235a098 | 2016-03-30 17:18:34 +0800 | [diff] [blame] | 258 | break; |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 259 | case Opt_recover_session: |
| 260 | if (!strncmp(argstr[0].from, "no", |
| 261 | argstr[0].to - argstr[0].from)) { |
| 262 | fsopt->flags &= ~CEPH_MOUNT_OPT_CLEANRECOVER; |
| 263 | } else if (!strncmp(argstr[0].from, "clean", |
| 264 | argstr[0].to - argstr[0].from)) { |
| 265 | fsopt->flags |= CEPH_MOUNT_OPT_CLEANRECOVER; |
| 266 | } else { |
| 267 | return -EINVAL; |
| 268 | } |
| 269 | break; |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 270 | case Opt_fscache_uniq: |
Chengguang Xu | 937441f | 2018-02-06 08:25:55 +0800 | [diff] [blame] | 271 | kfree(fsopt->fscache_uniq); |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 272 | fsopt->fscache_uniq = kstrndup(argstr[0].from, |
| 273 | argstr[0].to-argstr[0].from, |
| 274 | GFP_KERNEL); |
| 275 | if (!fsopt->fscache_uniq) |
| 276 | return -ENOMEM; |
| 277 | fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE; |
| 278 | break; |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 279 | /* misc */ |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 280 | case Opt_wsize: |
Chengguang Xu | 8db0c75 | 2018-05-30 16:47:06 +0800 | [diff] [blame] | 281 | if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_WRITE_SIZE) |
Yan, Zheng | 95cca2b | 2017-07-11 17:34:46 +0800 | [diff] [blame] | 282 | return -EINVAL; |
| 283 | fsopt->wsize = ALIGN(intval, PAGE_SIZE); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 284 | break; |
| 285 | case Opt_rsize: |
Chengguang Xu | 8db0c75 | 2018-05-30 16:47:06 +0800 | [diff] [blame] | 286 | if (intval < (int)PAGE_SIZE || intval > CEPH_MAX_READ_SIZE) |
Yan, Zheng | aa18792 | 2017-07-11 15:56:09 +0800 | [diff] [blame] | 287 | return -EINVAL; |
| 288 | fsopt->rsize = ALIGN(intval, PAGE_SIZE); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 289 | break; |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 290 | case Opt_rasize: |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 291 | if (intval < 0) |
| 292 | return -EINVAL; |
Chengguang Xu | c36ed50 | 2018-05-30 10:13:11 +0800 | [diff] [blame] | 293 | fsopt->rasize = ALIGN(intval, PAGE_SIZE); |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 294 | break; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 295 | case Opt_caps_wanted_delay_min: |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 296 | if (intval < 1) |
| 297 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 298 | fsopt->caps_wanted_delay_min = intval; |
| 299 | break; |
| 300 | case Opt_caps_wanted_delay_max: |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 301 | if (intval < 1) |
| 302 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 303 | fsopt->caps_wanted_delay_max = intval; |
| 304 | break; |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 305 | case Opt_caps_max: |
| 306 | if (intval < 0) |
| 307 | return -EINVAL; |
| 308 | fsopt->caps_max = intval; |
| 309 | break; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 310 | case Opt_readdir_max_entries: |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 311 | if (intval < 1) |
| 312 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 313 | fsopt->max_readdir = intval; |
| 314 | break; |
| 315 | case Opt_readdir_max_bytes: |
Chengguang Xu | 8db0c75 | 2018-05-30 16:47:06 +0800 | [diff] [blame] | 316 | if (intval < (int)PAGE_SIZE && intval != 0) |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 317 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 318 | fsopt->max_readdir_bytes = intval; |
| 319 | break; |
| 320 | case Opt_congestion_kb: |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 321 | if (intval < 1024) /* at least 1M */ |
| 322 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 323 | fsopt->congestion_kb = intval; |
| 324 | break; |
| 325 | case Opt_dirstat: |
| 326 | fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT; |
| 327 | break; |
| 328 | case Opt_nodirstat: |
| 329 | fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT; |
| 330 | break; |
| 331 | case Opt_rbytes: |
| 332 | fsopt->flags |= CEPH_MOUNT_OPT_RBYTES; |
| 333 | break; |
| 334 | case Opt_norbytes: |
| 335 | fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES; |
| 336 | break; |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 337 | case Opt_asyncreaddir: |
| 338 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR; |
| 339 | break; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 340 | case Opt_noasyncreaddir: |
| 341 | fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR; |
| 342 | break; |
Sage Weil | a40dc6c | 2012-01-10 09:12:55 -0800 | [diff] [blame] | 343 | case Opt_dcache: |
| 344 | fsopt->flags |= CEPH_MOUNT_OPT_DCACHE; |
| 345 | break; |
| 346 | case Opt_nodcache: |
| 347 | fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE; |
| 348 | break; |
Yehuda Sadeh | ad1fee9 | 2011-01-21 16:44:03 -0800 | [diff] [blame] | 349 | case Opt_ino32: |
| 350 | fsopt->flags |= CEPH_MOUNT_OPT_INO32; |
| 351 | break; |
Alex Elder | cffaba1 | 2012-02-15 07:43:54 -0600 | [diff] [blame] | 352 | case Opt_noino32: |
| 353 | fsopt->flags &= ~CEPH_MOUNT_OPT_INO32; |
| 354 | break; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 355 | case Opt_fscache: |
| 356 | fsopt->flags |= CEPH_MOUNT_OPT_FSCACHE; |
Chengguang Xu | 7ae7a82 | 2018-02-07 10:27:06 +0800 | [diff] [blame] | 357 | kfree(fsopt->fscache_uniq); |
| 358 | fsopt->fscache_uniq = NULL; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 359 | break; |
| 360 | case Opt_nofscache: |
| 361 | fsopt->flags &= ~CEPH_MOUNT_OPT_FSCACHE; |
Chengguang Xu | 7ae7a82 | 2018-02-07 10:27:06 +0800 | [diff] [blame] | 362 | kfree(fsopt->fscache_uniq); |
| 363 | fsopt->fscache_uniq = NULL; |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 364 | break; |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 365 | case Opt_poolperm: |
| 366 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOPOOLPERM; |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 367 | break; |
| 368 | case Opt_nopoolperm: |
| 369 | fsopt->flags |= CEPH_MOUNT_OPT_NOPOOLPERM; |
| 370 | break; |
Yan, Zheng | e9e427f | 2016-11-10 16:02:06 +0800 | [diff] [blame] | 371 | case Opt_require_active_mds: |
| 372 | fsopt->flags &= ~CEPH_MOUNT_OPT_MOUNTWAIT; |
| 373 | break; |
| 374 | case Opt_norequire_active_mds: |
| 375 | fsopt->flags |= CEPH_MOUNT_OPT_MOUNTWAIT; |
| 376 | break; |
Luis Henriques | 9122eed | 2018-01-31 10:53:13 +0000 | [diff] [blame] | 377 | case Opt_quotadf: |
| 378 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOQUOTADF; |
| 379 | break; |
| 380 | case Opt_noquotadf: |
| 381 | fsopt->flags |= CEPH_MOUNT_OPT_NOQUOTADF; |
| 382 | break; |
Luis Henriques | ea4cdc5 | 2018-10-15 16:46:00 +0100 | [diff] [blame] | 383 | case Opt_copyfrom: |
| 384 | fsopt->flags &= ~CEPH_MOUNT_OPT_NOCOPYFROM; |
| 385 | break; |
| 386 | case Opt_nocopyfrom: |
| 387 | fsopt->flags |= CEPH_MOUNT_OPT_NOCOPYFROM; |
| 388 | break; |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 389 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
| 390 | case Opt_acl: |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 391 | fsopt->sb_flags |= SB_POSIXACL; |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 392 | break; |
| 393 | #endif |
| 394 | case Opt_noacl: |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 395 | fsopt->sb_flags &= ~SB_POSIXACL; |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 396 | break; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 397 | default: |
| 398 | BUG_ON(token); |
| 399 | } |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static void destroy_mount_options(struct ceph_mount_options *args) |
| 404 | { |
| 405 | dout("destroy_mount_options %p\n", args); |
| 406 | kfree(args->snapdir_name); |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 407 | kfree(args->mds_namespace); |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 408 | kfree(args->server_path); |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 409 | kfree(args->fscache_uniq); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 410 | kfree(args); |
| 411 | } |
| 412 | |
| 413 | static int strcmp_null(const char *s1, const char *s2) |
| 414 | { |
| 415 | if (!s1 && !s2) |
| 416 | return 0; |
| 417 | if (s1 && !s2) |
| 418 | return -1; |
| 419 | if (!s1 && s2) |
| 420 | return 1; |
| 421 | return strcmp(s1, s2); |
| 422 | } |
| 423 | |
| 424 | static int compare_mount_options(struct ceph_mount_options *new_fsopt, |
| 425 | struct ceph_options *new_opt, |
| 426 | struct ceph_fs_client *fsc) |
| 427 | { |
| 428 | struct ceph_mount_options *fsopt1 = new_fsopt; |
| 429 | struct ceph_mount_options *fsopt2 = fsc->mount_options; |
| 430 | int ofs = offsetof(struct ceph_mount_options, snapdir_name); |
| 431 | int ret; |
| 432 | |
| 433 | ret = memcmp(fsopt1, fsopt2, ofs); |
| 434 | if (ret) |
| 435 | return ret; |
| 436 | |
| 437 | ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name); |
| 438 | if (ret) |
| 439 | return ret; |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 440 | ret = strcmp_null(fsopt1->mds_namespace, fsopt2->mds_namespace); |
| 441 | if (ret) |
| 442 | return ret; |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 443 | ret = strcmp_null(fsopt1->server_path, fsopt2->server_path); |
| 444 | if (ret) |
| 445 | return ret; |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 446 | ret = strcmp_null(fsopt1->fscache_uniq, fsopt2->fscache_uniq); |
| 447 | if (ret) |
| 448 | return ret; |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 449 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 450 | return ceph_compare_options(new_opt, fsc->client); |
| 451 | } |
| 452 | |
| 453 | static int parse_mount_options(struct ceph_mount_options **pfsopt, |
| 454 | struct ceph_options **popt, |
| 455 | int flags, char *options, |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 456 | const char *dev_name) |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 457 | { |
| 458 | struct ceph_mount_options *fsopt; |
| 459 | const char *dev_name_end; |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 460 | int err; |
| 461 | |
| 462 | if (!dev_name || !*dev_name) |
| 463 | return -EINVAL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 464 | |
| 465 | fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL); |
| 466 | if (!fsopt) |
| 467 | return -ENOMEM; |
| 468 | |
| 469 | dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name); |
| 470 | |
Noah Watkins | 80db8be | 2011-08-22 13:49:23 -0600 | [diff] [blame] | 471 | fsopt->sb_flags = flags; |
| 472 | fsopt->flags = CEPH_MOUNT_OPT_DEFAULT; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 473 | |
Yan, Zheng | 95cca2b | 2017-07-11 17:34:46 +0800 | [diff] [blame] | 474 | fsopt->wsize = CEPH_MAX_WRITE_SIZE; |
Yan, Zheng | aa18792 | 2017-07-11 15:56:09 +0800 | [diff] [blame] | 475 | fsopt->rsize = CEPH_MAX_READ_SIZE; |
Noah Watkins | 80db8be | 2011-08-22 13:49:23 -0600 | [diff] [blame] | 476 | fsopt->rasize = CEPH_RASIZE_DEFAULT; |
| 477 | fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL); |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 478 | if (!fsopt->snapdir_name) { |
| 479 | err = -ENOMEM; |
| 480 | goto out; |
| 481 | } |
| 482 | |
Sage Weil | 50aac4f | 2011-01-18 07:59:40 -0800 | [diff] [blame] | 483 | fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT; |
| 484 | fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT; |
Noah Watkins | 80db8be | 2011-08-22 13:49:23 -0600 | [diff] [blame] | 485 | fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT; |
| 486 | fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT; |
| 487 | fsopt->congestion_kb = default_congestion_kb(); |
| 488 | |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 489 | /* |
| 490 | * Distinguish the server list from the path in "dev_name". |
| 491 | * Internally we do not include the leading '/' in the path. |
| 492 | * |
| 493 | * "dev_name" will look like: |
| 494 | * <server_spec>[,<server_spec>...]:[<path>] |
| 495 | * where |
| 496 | * <server_spec> is <ip>[:<port>] |
| 497 | * <path> is optional, but if present must begin with '/' |
| 498 | */ |
| 499 | dev_name_end = strchr(dev_name, '/'); |
| 500 | if (dev_name_end) { |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 501 | if (strlen(dev_name_end) > 1) { |
| 502 | fsopt->server_path = kstrdup(dev_name_end, GFP_KERNEL); |
| 503 | if (!fsopt->server_path) { |
| 504 | err = -ENOMEM; |
| 505 | goto out; |
| 506 | } |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 507 | } |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 508 | } else { |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 509 | dev_name_end = dev_name + strlen(dev_name); |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 510 | } |
Noah Watkins | 80db8be | 2011-08-22 13:49:23 -0600 | [diff] [blame] | 511 | err = -EINVAL; |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 512 | dev_name_end--; /* back up to ':' separator */ |
Sasha Levin | 5446429 | 2013-07-01 18:33:39 -0400 | [diff] [blame] | 513 | if (dev_name_end < dev_name || *dev_name_end != ':') { |
Alex Elder | c98f533 | 2012-08-09 10:33:26 -0700 | [diff] [blame] | 514 | pr_err("device name is missing path (no : separator in %s)\n", |
Noah Watkins | 80db8be | 2011-08-22 13:49:23 -0600 | [diff] [blame] | 515 | dev_name); |
| 516 | goto out; |
| 517 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 518 | dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name); |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 519 | if (fsopt->server_path) |
| 520 | dout("server path '%s'\n", fsopt->server_path); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 521 | |
Alex Elder | ee57741 | 2012-01-24 10:08:36 -0600 | [diff] [blame] | 522 | *popt = ceph_parse_options(options, dev_name, dev_name_end, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 523 | parse_fsopt_token, (void *)fsopt); |
Alex Elder | ee57741 | 2012-01-24 10:08:36 -0600 | [diff] [blame] | 524 | if (IS_ERR(*popt)) { |
| 525 | err = PTR_ERR(*popt); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 526 | goto out; |
Alex Elder | ee57741 | 2012-01-24 10:08:36 -0600 | [diff] [blame] | 527 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 528 | |
| 529 | /* success */ |
| 530 | *pfsopt = fsopt; |
| 531 | return 0; |
| 532 | |
| 533 | out: |
| 534 | destroy_mount_options(fsopt); |
| 535 | return err; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 538 | /** |
| 539 | * ceph_show_options - Show mount options in /proc/mounts |
| 540 | * @m: seq_file to write to |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 541 | * @root: root of that (sub)tree |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 542 | */ |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 543 | static int ceph_show_options(struct seq_file *m, struct dentry *root) |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 544 | { |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 545 | struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 546 | struct ceph_mount_options *fsopt = fsc->mount_options; |
Ilya Dryomov | ff40f9a | 2015-03-25 21:02:16 +0300 | [diff] [blame] | 547 | size_t pos; |
| 548 | int ret; |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 549 | |
Ilya Dryomov | ff40f9a | 2015-03-25 21:02:16 +0300 | [diff] [blame] | 550 | /* a comma between MNT/MS and client options */ |
| 551 | seq_putc(m, ','); |
| 552 | pos = m->count; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 553 | |
Dongsheng Yang | 02b2f54 | 2018-12-18 04:31:48 -0500 | [diff] [blame] | 554 | ret = ceph_print_client_options(m, fsc->client, false); |
Ilya Dryomov | ff40f9a | 2015-03-25 21:02:16 +0300 | [diff] [blame] | 555 | if (ret) |
| 556 | return ret; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 557 | |
Ilya Dryomov | ff40f9a | 2015-03-25 21:02:16 +0300 | [diff] [blame] | 558 | /* retract our comma if no client options */ |
| 559 | if (m->count == pos) |
| 560 | m->count--; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 561 | |
| 562 | if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT) |
| 563 | seq_puts(m, ",dirstat"); |
Yan, Zheng | 133e915 | 2016-01-25 10:44:33 +0800 | [diff] [blame] | 564 | if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES)) |
| 565 | seq_puts(m, ",rbytes"); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 566 | if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR) |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 567 | seq_puts(m, ",noasyncreaddir"); |
Ilya Dryomov | ff7eeb8 | 2015-03-25 21:10:09 +0300 | [diff] [blame] | 568 | if ((fsopt->flags & CEPH_MOUNT_OPT_DCACHE) == 0) |
Sage Weil | a40dc6c | 2012-01-10 09:12:55 -0800 | [diff] [blame] | 569 | seq_puts(m, ",nodcache"); |
Chengguang Xu | 3619aa8 | 2018-06-04 16:03:51 +0800 | [diff] [blame] | 570 | if (fsopt->flags & CEPH_MOUNT_OPT_INO32) |
| 571 | seq_puts(m, ",ino32"); |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 572 | if (fsopt->flags & CEPH_MOUNT_OPT_FSCACHE) { |
Chengguang Xu | 4d8969a | 2018-02-15 15:39:05 +0800 | [diff] [blame] | 573 | seq_show_option(m, "fsc", fsopt->fscache_uniq); |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 574 | } |
Yan, Zheng | 10183a6 | 2015-04-27 15:33:28 +0800 | [diff] [blame] | 575 | if (fsopt->flags & CEPH_MOUNT_OPT_NOPOOLPERM) |
| 576 | seq_puts(m, ",nopoolperm"); |
Luis Henriques | 9122eed | 2018-01-31 10:53:13 +0000 | [diff] [blame] | 577 | if (fsopt->flags & CEPH_MOUNT_OPT_NOQUOTADF) |
| 578 | seq_puts(m, ",noquotadf"); |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 579 | |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 580 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 581 | if (fsopt->sb_flags & SB_POSIXACL) |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 582 | seq_puts(m, ",acl"); |
| 583 | else |
| 584 | seq_puts(m, ",noacl"); |
| 585 | #endif |
| 586 | |
Luis Henriques | 6f9718f | 2018-12-10 10:23:12 +0000 | [diff] [blame] | 587 | if ((fsopt->flags & CEPH_MOUNT_OPT_NOCOPYFROM) == 0) |
| 588 | seq_puts(m, ",copyfrom"); |
Luis Henriques | ea4cdc5 | 2018-10-15 16:46:00 +0100 | [diff] [blame] | 589 | |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 590 | if (fsopt->mds_namespace) |
Chengguang Xu | 4d8969a | 2018-02-15 15:39:05 +0800 | [diff] [blame] | 591 | seq_show_option(m, "mds_namespace", fsopt->mds_namespace); |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 592 | |
| 593 | if (fsopt->flags & CEPH_MOUNT_OPT_CLEANRECOVER) |
| 594 | seq_show_option(m, "recover_session", "clean"); |
| 595 | |
Ilya Dryomov | 6dd4940 | 2018-05-03 16:26:55 +0200 | [diff] [blame] | 596 | if (fsopt->wsize != CEPH_MAX_WRITE_SIZE) |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 597 | seq_printf(m, ",wsize=%d", fsopt->wsize); |
Yan, Zheng | aa18792 | 2017-07-11 15:56:09 +0800 | [diff] [blame] | 598 | if (fsopt->rsize != CEPH_MAX_READ_SIZE) |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 599 | seq_printf(m, ",rsize=%d", fsopt->rsize); |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 600 | if (fsopt->rasize != CEPH_RASIZE_DEFAULT) |
Sage Weil | 2151937 | 2011-12-01 08:06:52 -0800 | [diff] [blame] | 601 | seq_printf(m, ",rasize=%d", fsopt->rasize); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 602 | if (fsopt->congestion_kb != default_congestion_kb()) |
| 603 | seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb); |
Yan, Zheng | fe33032 | 2019-02-01 14:57:15 +0800 | [diff] [blame] | 604 | if (fsopt->caps_max) |
| 605 | seq_printf(m, ",caps_max=%d", fsopt->caps_max); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 606 | if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT) |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 607 | seq_printf(m, ",caps_wanted_delay_min=%d", |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 608 | fsopt->caps_wanted_delay_min); |
| 609 | if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT) |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 610 | seq_printf(m, ",caps_wanted_delay_max=%d", |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 611 | fsopt->caps_wanted_delay_max); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 612 | if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT) |
| 613 | seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir); |
| 614 | if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT) |
| 615 | seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes); |
| 616 | if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT)) |
Kees Cook | a068acf | 2015-09-04 15:44:57 -0700 | [diff] [blame] | 617 | seq_show_option(m, "snapdirname", fsopt->snapdir_name); |
Ilya Dryomov | ff40f9a | 2015-03-25 21:02:16 +0300 | [diff] [blame] | 618 | |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | /* |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 623 | * handle any mon messages the standard library doesn't understand. |
| 624 | * return error if we don't either. |
| 625 | */ |
| 626 | static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg) |
| 627 | { |
| 628 | struct ceph_fs_client *fsc = client->private; |
| 629 | int type = le16_to_cpu(msg->hdr.type); |
| 630 | |
| 631 | switch (type) { |
| 632 | case CEPH_MSG_MDS_MAP: |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 633 | ceph_mdsc_handle_mdsmap(fsc->mdsc, msg); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 634 | return 0; |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 635 | case CEPH_MSG_FS_MAP_USER: |
| 636 | ceph_mdsc_handle_fsmap(fsc->mdsc, msg); |
| 637 | return 0; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 638 | default: |
| 639 | return -1; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * create a new fs client |
Ilya Dryomov | 8aaff15 | 2018-08-24 15:32:43 +0200 | [diff] [blame] | 645 | * |
| 646 | * Success or not, this function consumes @fsopt and @opt. |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 647 | */ |
H Hartley Sweeten | 0c6d4b4e2 | 2011-09-23 11:53:30 -0700 | [diff] [blame] | 648 | static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt, |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 649 | struct ceph_options *opt) |
| 650 | { |
| 651 | struct ceph_fs_client *fsc; |
Alex Elder | 3bf5333 | 2013-04-01 10:48:40 -0500 | [diff] [blame] | 652 | int page_count; |
| 653 | size_t size; |
Ilya Dryomov | 8aaff15 | 2018-08-24 15:32:43 +0200 | [diff] [blame] | 654 | int err; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 655 | |
| 656 | fsc = kzalloc(sizeof(*fsc), GFP_KERNEL); |
Ilya Dryomov | 8aaff15 | 2018-08-24 15:32:43 +0200 | [diff] [blame] | 657 | if (!fsc) { |
| 658 | err = -ENOMEM; |
| 659 | goto fail; |
| 660 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 661 | |
Ilya Dryomov | 74da4a0f | 2017-03-03 18:16:07 +0100 | [diff] [blame] | 662 | fsc->client = ceph_create_client(opt, fsc); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 663 | if (IS_ERR(fsc->client)) { |
| 664 | err = PTR_ERR(fsc->client); |
| 665 | goto fail; |
| 666 | } |
Ilya Dryomov | 8aaff15 | 2018-08-24 15:32:43 +0200 | [diff] [blame] | 667 | opt = NULL; /* fsc->client now owns this */ |
Ilya Dryomov | c843d13 | 2018-05-30 16:29:14 +0200 | [diff] [blame] | 668 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 669 | fsc->client->extra_mon_dispatch = extra_mon_dispatch; |
Dongsheng Yang | 02b2f54 | 2018-12-18 04:31:48 -0500 | [diff] [blame] | 670 | ceph_set_opt(fsc->client, ABORT_ON_FULL); |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 671 | |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 672 | if (!fsopt->mds_namespace) { |
Yan, Zheng | 430afba | 2016-07-08 11:25:38 +0800 | [diff] [blame] | 673 | ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_MDSMAP, |
| 674 | 0, true); |
| 675 | } else { |
| 676 | ceph_monc_want_map(&fsc->client->monc, CEPH_SUB_FSMAP, |
| 677 | 0, false); |
| 678 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 679 | |
| 680 | fsc->mount_options = fsopt; |
| 681 | |
| 682 | fsc->sb = NULL; |
| 683 | fsc->mount_state = CEPH_MOUNT_MOUNTING; |
Yan, Zheng | 81f148a | 2019-07-25 20:16:46 +0800 | [diff] [blame] | 684 | fsc->filp_gen = 1; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 685 | |
| 686 | atomic_long_set(&fsc->writeback_count, 0); |
| 687 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 688 | err = -ENOMEM; |
Tejun Heo | 01e6acc | 2011-01-03 14:49:45 +0100 | [diff] [blame] | 689 | /* |
| 690 | * The number of concurrent works can be high but they don't need |
| 691 | * to be processed in parallel, limit concurrency. |
| 692 | */ |
Yan, Zheng | 1cf89a8 | 2019-05-18 11:18:44 +0800 | [diff] [blame] | 693 | fsc->inode_wq = alloc_workqueue("ceph-inode", WQ_UNBOUND, 0); |
| 694 | if (!fsc->inode_wq) |
Jan Kara | 09dc9fc | 2017-04-12 12:24:33 +0200 | [diff] [blame] | 695 | goto fail_client; |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 696 | fsc->cap_wq = alloc_workqueue("ceph-cap", 0, 1); |
| 697 | if (!fsc->cap_wq) |
Yan, Zheng | 1cf89a8 | 2019-05-18 11:18:44 +0800 | [diff] [blame] | 698 | goto fail_inode_wq; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 699 | |
| 700 | /* set up mempools */ |
| 701 | err = -ENOMEM; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 702 | page_count = fsc->mount_options->wsize >> PAGE_SHIFT; |
Alex Elder | 3bf5333 | 2013-04-01 10:48:40 -0500 | [diff] [blame] | 703 | size = sizeof (struct page *) * (page_count ? page_count : 1); |
| 704 | fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10, size); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 705 | if (!fsc->wb_pagevec_pool) |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 706 | goto fail_cap_wq; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 707 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 708 | return fsc; |
| 709 | |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 710 | fail_cap_wq: |
| 711 | destroy_workqueue(fsc->cap_wq); |
Yan, Zheng | 1cf89a8 | 2019-05-18 11:18:44 +0800 | [diff] [blame] | 712 | fail_inode_wq: |
| 713 | destroy_workqueue(fsc->inode_wq); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 714 | fail_client: |
| 715 | ceph_destroy_client(fsc->client); |
| 716 | fail: |
| 717 | kfree(fsc); |
Ilya Dryomov | 8aaff15 | 2018-08-24 15:32:43 +0200 | [diff] [blame] | 718 | if (opt) |
| 719 | ceph_destroy_options(opt); |
| 720 | destroy_mount_options(fsopt); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 721 | return ERR_PTR(err); |
| 722 | } |
| 723 | |
Yan, Zheng | a57d906 | 2018-05-18 16:05:51 +0800 | [diff] [blame] | 724 | static void flush_fs_workqueues(struct ceph_fs_client *fsc) |
| 725 | { |
Yan, Zheng | 1cf89a8 | 2019-05-18 11:18:44 +0800 | [diff] [blame] | 726 | flush_workqueue(fsc->inode_wq); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 727 | flush_workqueue(fsc->cap_wq); |
Yan, Zheng | a57d906 | 2018-05-18 16:05:51 +0800 | [diff] [blame] | 728 | } |
| 729 | |
H Hartley Sweeten | 0c6d4b4e2 | 2011-09-23 11:53:30 -0700 | [diff] [blame] | 730 | static void destroy_fs_client(struct ceph_fs_client *fsc) |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 731 | { |
| 732 | dout("destroy_fs_client %p\n", fsc); |
| 733 | |
Jeff Layton | 3ee5a70 | 2019-09-12 08:07:56 -0400 | [diff] [blame^] | 734 | ceph_mdsc_destroy(fsc); |
Yan, Zheng | 1cf89a8 | 2019-05-18 11:18:44 +0800 | [diff] [blame] | 735 | destroy_workqueue(fsc->inode_wq); |
Yan, Zheng | e3ec8d6 | 2019-01-14 17:21:19 +0800 | [diff] [blame] | 736 | destroy_workqueue(fsc->cap_wq); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 737 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 738 | mempool_destroy(fsc->wb_pagevec_pool); |
| 739 | |
| 740 | destroy_mount_options(fsc->mount_options); |
| 741 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 742 | ceph_destroy_client(fsc->client); |
| 743 | |
| 744 | kfree(fsc); |
| 745 | dout("destroy_fs_client %p done\n", fsc); |
| 746 | } |
| 747 | |
| 748 | /* |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 749 | * caches |
| 750 | */ |
| 751 | struct kmem_cache *ceph_inode_cachep; |
| 752 | struct kmem_cache *ceph_cap_cachep; |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 753 | struct kmem_cache *ceph_cap_flush_cachep; |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 754 | struct kmem_cache *ceph_dentry_cachep; |
| 755 | struct kmem_cache *ceph_file_cachep; |
Chengguang Xu | bb48bd4 | 2018-03-13 10:42:44 +0800 | [diff] [blame] | 756 | struct kmem_cache *ceph_dir_file_cachep; |
Sage Weil | 6e19a16 | 2010-04-29 16:38:32 -0700 | [diff] [blame] | 757 | |
| 758 | static void ceph_inode_init_once(void *foo) |
| 759 | { |
| 760 | struct ceph_inode_info *ci = foo; |
| 761 | inode_init_once(&ci->vfs_inode); |
| 762 | } |
| 763 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 764 | static int __init init_caches(void) |
| 765 | { |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 766 | int error = -ENOMEM; |
| 767 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 768 | ceph_inode_cachep = kmem_cache_create("ceph_inode_info", |
| 769 | sizeof(struct ceph_inode_info), |
| 770 | __alignof__(struct ceph_inode_info), |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 771 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD| |
| 772 | SLAB_ACCOUNT, ceph_inode_init_once); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 773 | if (!ceph_inode_cachep) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 774 | return -ENOMEM; |
| 775 | |
Chengguang Xu | bc4b5ad | 2018-02-27 13:49:44 +0800 | [diff] [blame] | 776 | ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 777 | if (!ceph_cap_cachep) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 778 | goto bad_cap; |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 779 | ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush, |
| 780 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 781 | if (!ceph_cap_flush_cachep) |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 782 | goto bad_cap_flush; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 783 | |
| 784 | ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info, |
| 785 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 786 | if (!ceph_dentry_cachep) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 787 | goto bad_dentry; |
| 788 | |
Nikolay Borisov | 6b1a9a6 | 2016-07-25 20:12:13 +0300 | [diff] [blame] | 789 | ceph_file_cachep = KMEM_CACHE(ceph_file_info, SLAB_MEM_SPREAD); |
Markus Elfring | d37b1d9 | 2017-08-20 20:22:02 +0200 | [diff] [blame] | 790 | if (!ceph_file_cachep) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 791 | goto bad_file; |
| 792 | |
Chengguang Xu | bb48bd4 | 2018-03-13 10:42:44 +0800 | [diff] [blame] | 793 | ceph_dir_file_cachep = KMEM_CACHE(ceph_dir_file_info, SLAB_MEM_SPREAD); |
| 794 | if (!ceph_dir_file_cachep) |
| 795 | goto bad_dir_file; |
| 796 | |
Chengguang Xu | 1c78924 | 2018-03-01 14:24:51 +0800 | [diff] [blame] | 797 | error = ceph_fscache_register(); |
| 798 | if (error) |
| 799 | goto bad_fscache; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 800 | |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 801 | return 0; |
Chengguang Xu | 1c78924 | 2018-03-01 14:24:51 +0800 | [diff] [blame] | 802 | |
| 803 | bad_fscache: |
Chengguang Xu | bb48bd4 | 2018-03-13 10:42:44 +0800 | [diff] [blame] | 804 | kmem_cache_destroy(ceph_dir_file_cachep); |
| 805 | bad_dir_file: |
Chengguang Xu | 1c78924 | 2018-03-01 14:24:51 +0800 | [diff] [blame] | 806 | kmem_cache_destroy(ceph_file_cachep); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 807 | bad_file: |
| 808 | kmem_cache_destroy(ceph_dentry_cachep); |
| 809 | bad_dentry: |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 810 | kmem_cache_destroy(ceph_cap_flush_cachep); |
| 811 | bad_cap_flush: |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 812 | kmem_cache_destroy(ceph_cap_cachep); |
| 813 | bad_cap: |
| 814 | kmem_cache_destroy(ceph_inode_cachep); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 815 | return error; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | static void destroy_caches(void) |
| 819 | { |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 820 | /* |
| 821 | * Make sure all delayed rcu free inodes are flushed before we |
| 822 | * destroy cache. |
| 823 | */ |
| 824 | rcu_barrier(); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 825 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 826 | kmem_cache_destroy(ceph_inode_cachep); |
| 827 | kmem_cache_destroy(ceph_cap_cachep); |
Yan, Zheng | f66fd9f | 2015-06-10 17:26:13 +0800 | [diff] [blame] | 828 | kmem_cache_destroy(ceph_cap_flush_cachep); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 829 | kmem_cache_destroy(ceph_dentry_cachep); |
| 830 | kmem_cache_destroy(ceph_file_cachep); |
Chengguang Xu | bb48bd4 | 2018-03-13 10:42:44 +0800 | [diff] [blame] | 831 | kmem_cache_destroy(ceph_dir_file_cachep); |
Milosz Tanski | 99ccbd2 | 2013-08-21 17:29:54 -0400 | [diff] [blame] | 832 | |
| 833 | ceph_fscache_unregister(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | |
| 837 | /* |
| 838 | * ceph_umount_begin - initiate forced umount. Tear down down the |
| 839 | * mount, skipping steps that may hang while waiting for server(s). |
| 840 | */ |
| 841 | static void ceph_umount_begin(struct super_block *sb) |
| 842 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 843 | struct ceph_fs_client *fsc = ceph_sb_to_client(sb); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 844 | |
| 845 | dout("ceph_umount_begin - starting forced umount\n"); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 846 | if (!fsc) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 847 | return; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 848 | fsc->mount_state = CEPH_MOUNT_SHUTDOWN; |
Yan, Zheng | 12b69d5 | 2018-05-11 17:12:02 +0800 | [diff] [blame] | 849 | ceph_osdc_abort_requests(&fsc->client->osdc, -EIO); |
Yan, Zheng | 48fec5d | 2015-07-01 16:27:46 +0800 | [diff] [blame] | 850 | ceph_mdsc_force_umount(fsc->mdsc); |
Yan, Zheng | 81f148a | 2019-07-25 20:16:46 +0800 | [diff] [blame] | 851 | fsc->filp_gen++; // invalidate open files |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Jeff Layton | 00abf69 | 2019-05-07 09:20:54 -0400 | [diff] [blame] | 854 | static int ceph_remount(struct super_block *sb, int *flags, char *data) |
| 855 | { |
| 856 | sync_filesystem(sb); |
| 857 | return 0; |
| 858 | } |
| 859 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 860 | static const struct super_operations ceph_super_ops = { |
| 861 | .alloc_inode = ceph_alloc_inode, |
Al Viro | cfa6d41 | 2019-04-10 15:18:50 -0400 | [diff] [blame] | 862 | .free_inode = ceph_free_inode, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 863 | .write_inode = ceph_write_inode, |
Luis Henriques | 52dd0f1 | 2019-07-05 17:14:56 +0100 | [diff] [blame] | 864 | .drop_inode = generic_delete_inode, |
Yan, Zheng | 87bc5b8 | 2019-06-02 09:45:38 +0800 | [diff] [blame] | 865 | .evict_inode = ceph_evict_inode, |
Sage Weil | 2d9c98a | 2010-07-30 09:38:13 -0700 | [diff] [blame] | 866 | .sync_fs = ceph_sync_fs, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 867 | .put_super = ceph_put_super, |
Jeff Layton | 00abf69 | 2019-05-07 09:20:54 -0400 | [diff] [blame] | 868 | .remount_fs = ceph_remount, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 869 | .show_options = ceph_show_options, |
| 870 | .statfs = ceph_statfs, |
| 871 | .umount_begin = ceph_umount_begin, |
| 872 | }; |
| 873 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 874 | /* |
| 875 | * Bootstrap mount by opening the root directory. Note the mount |
| 876 | * @started time from caller, and time out if this takes too long. |
| 877 | */ |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 878 | static struct dentry *open_root_dentry(struct ceph_fs_client *fsc, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 879 | const char *path, |
| 880 | unsigned long started) |
| 881 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 882 | struct ceph_mds_client *mdsc = fsc->mdsc; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 883 | struct ceph_mds_request *req = NULL; |
| 884 | int err; |
| 885 | struct dentry *root; |
| 886 | |
| 887 | /* open dir */ |
| 888 | dout("open_root_inode opening '%s'\n", path); |
| 889 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS); |
| 890 | if (IS_ERR(req)) |
Julia Lawall | 7e34bc5 | 2010-05-22 12:01:14 +0200 | [diff] [blame] | 891 | return ERR_CAST(req); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 892 | req->r_path1 = kstrdup(path, GFP_NOFS); |
Sanidhya Kashyap | a149bb9 | 2015-03-21 12:54:58 -0400 | [diff] [blame] | 893 | if (!req->r_path1) { |
| 894 | root = ERR_PTR(-ENOMEM); |
| 895 | goto out; |
| 896 | } |
| 897 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 898 | req->r_ino1.ino = CEPH_INO_ROOT; |
| 899 | req->r_ino1.snap = CEPH_NOSNAP; |
| 900 | req->r_started = started; |
Ilya Dryomov | a319bf5 | 2015-05-15 12:02:17 +0300 | [diff] [blame] | 901 | req->r_timeout = fsc->client->options->mount_timeout; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 902 | req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE); |
| 903 | req->r_num_caps = 2; |
| 904 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
| 905 | if (err == 0) { |
Al Viro | 3c5184e | 2012-01-09 16:34:32 -0500 | [diff] [blame] | 906 | struct inode *inode = req->r_target_inode; |
| 907 | req->r_target_inode = NULL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 908 | dout("open_root_inode success\n"); |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 909 | root = d_make_root(inode); |
| 910 | if (!root) { |
| 911 | root = ERR_PTR(-ENOMEM); |
| 912 | goto out; |
Sage Weil | 774ac21 | 2011-11-11 09:48:08 -0800 | [diff] [blame] | 913 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 914 | dout("open_root_inode success, root dentry is %p\n", root); |
| 915 | } else { |
| 916 | root = ERR_PTR(err); |
| 917 | } |
Al Viro | 3c5184e | 2012-01-09 16:34:32 -0500 | [diff] [blame] | 918 | out: |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 919 | ceph_mdsc_put_request(req); |
| 920 | return root; |
| 921 | } |
| 922 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 923 | |
| 924 | |
| 925 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 926 | /* |
| 927 | * mount: join the ceph cluster, and open root directory. |
| 928 | */ |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 929 | static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 930 | { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 931 | int err; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 932 | unsigned long started = jiffies; /* note the start time */ |
| 933 | struct dentry *root; |
| 934 | |
Yan, Zheng | 132ca7e | 2016-03-12 13:20:48 +0800 | [diff] [blame] | 935 | dout("mount start %p\n", fsc); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 936 | mutex_lock(&fsc->client->mount_mutex); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 937 | |
Yan, Zheng | 132ca7e | 2016-03-12 13:20:48 +0800 | [diff] [blame] | 938 | if (!fsc->sb->s_root) { |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 939 | const char *path; |
Yan, Zheng | 132ca7e | 2016-03-12 13:20:48 +0800 | [diff] [blame] | 940 | err = __ceph_open_session(fsc->client, started); |
| 941 | if (err < 0) |
| 942 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 943 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 944 | /* setup fscache */ |
| 945 | if (fsc->mount_options->flags & CEPH_MOUNT_OPT_FSCACHE) { |
| 946 | err = ceph_fscache_register_fs(fsc); |
| 947 | if (err < 0) |
| 948 | goto out; |
| 949 | } |
| 950 | |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 951 | if (!fsc->mount_options->server_path) { |
| 952 | path = ""; |
| 953 | dout("mount opening path \\t\n"); |
| 954 | } else { |
| 955 | path = fsc->mount_options->server_path + 1; |
| 956 | dout("mount opening path %s\n", path); |
| 957 | } |
Chengguang Xu | 1810673 | 2018-02-09 20:40:59 +0800 | [diff] [blame] | 958 | |
Greg Kroah-Hartman | 1a829ff | 2019-06-12 16:55:38 +0200 | [diff] [blame] | 959 | ceph_fs_debugfs_init(fsc); |
Chengguang Xu | 1810673 | 2018-02-09 20:40:59 +0800 | [diff] [blame] | 960 | |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 961 | root = open_root_dentry(fsc, path, started); |
Yan, Zheng | 132ca7e | 2016-03-12 13:20:48 +0800 | [diff] [blame] | 962 | if (IS_ERR(root)) { |
| 963 | err = PTR_ERR(root); |
| 964 | goto out; |
| 965 | } |
Yan, Zheng | ce2728a | 2016-09-14 14:53:05 +0800 | [diff] [blame] | 966 | fsc->sb->s_root = dget(root); |
Geert Uytterhoeven | 31ca587 | 2016-10-13 17:15:37 +0200 | [diff] [blame] | 967 | } else { |
| 968 | root = dget(fsc->sb->s_root); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 969 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 970 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 971 | fsc->mount_state = CEPH_MOUNT_MOUNTED; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 972 | dout("mount success\n"); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 973 | mutex_unlock(&fsc->client->mount_mutex); |
| 974 | return root; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 975 | |
Yan, Zheng | 132ca7e | 2016-03-12 13:20:48 +0800 | [diff] [blame] | 976 | out: |
| 977 | mutex_unlock(&fsc->client->mount_mutex); |
| 978 | return ERR_PTR(err); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static int ceph_set_super(struct super_block *s, void *data) |
| 982 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 983 | struct ceph_fs_client *fsc = data; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 984 | int ret; |
| 985 | |
| 986 | dout("set_super %p data %p\n", s, data); |
| 987 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 988 | s->s_flags = fsc->mount_options->sb_flags; |
Chengguang Xu | 719784b | 2018-07-19 22:15:24 +0800 | [diff] [blame] | 989 | s->s_maxbytes = MAX_LFS_FILESIZE; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 990 | |
Guangliang Zhao | 7221fe4 | 2013-11-11 15:18:03 +0800 | [diff] [blame] | 991 | s->s_xattr = ceph_xattr_handlers; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 992 | s->s_fs_info = fsc; |
| 993 | fsc->sb = s; |
Chengguang Xu | 719784b | 2018-07-19 22:15:24 +0800 | [diff] [blame] | 994 | fsc->max_file_size = 1ULL << 40; /* temp value until we get mdsmap */ |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 995 | |
| 996 | s->s_op = &ceph_super_ops; |
Al Viro | 18fc8ab | 2016-10-28 21:52:50 -0400 | [diff] [blame] | 997 | s->s_d_op = &ceph_dentry_ops; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 998 | s->s_export_op = &ceph_export_ops; |
| 999 | |
Luis Henriques | 0f7cf80 | 2019-06-27 14:51:22 +0100 | [diff] [blame] | 1000 | s->s_time_gran = 1; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1001 | |
| 1002 | ret = set_anon_super(s, NULL); /* what is that second arg for? */ |
| 1003 | if (ret != 0) |
| 1004 | goto fail; |
| 1005 | |
| 1006 | return ret; |
| 1007 | |
| 1008 | fail: |
| 1009 | s->s_fs_info = NULL; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1010 | fsc->sb = NULL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1011 | return ret; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * share superblock if same fs AND options |
| 1016 | */ |
| 1017 | static int ceph_compare_super(struct super_block *sb, void *data) |
| 1018 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1019 | struct ceph_fs_client *new = data; |
| 1020 | struct ceph_mount_options *fsopt = new->mount_options; |
| 1021 | struct ceph_options *opt = new->client->options; |
| 1022 | struct ceph_fs_client *other = ceph_sb_to_client(sb); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1023 | |
| 1024 | dout("ceph_compare_super %p\n", sb); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1025 | |
| 1026 | if (compare_mount_options(fsopt, opt, other)) { |
| 1027 | dout("monitor(s)/mount options don't match\n"); |
| 1028 | return 0; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1029 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1030 | if ((opt->flags & CEPH_OPT_FSID) && |
| 1031 | ceph_fsid_compare(&opt->fsid, &other->client->fsid)) { |
| 1032 | dout("fsid doesn't match\n"); |
| 1033 | return 0; |
| 1034 | } |
| 1035 | if (fsopt->sb_flags != other->mount_options->sb_flags) { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1036 | dout("flags differ\n"); |
| 1037 | return 0; |
| 1038 | } |
| 1039 | return 1; |
| 1040 | } |
| 1041 | |
| 1042 | /* |
| 1043 | * construct our own bdi so we can control readahead, etc. |
| 1044 | */ |
Jeff Mahoney | 00d5643 | 2010-06-10 11:13:58 -0400 | [diff] [blame] | 1045 | static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0); |
Sage Weil | 31e0cf8 | 2010-05-04 16:39:35 -0700 | [diff] [blame] | 1046 | |
Jan Kara | 09dc9fc | 2017-04-12 12:24:33 +0200 | [diff] [blame] | 1047 | static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1048 | { |
| 1049 | int err; |
| 1050 | |
Jan Kara | 09dc9fc | 2017-04-12 12:24:33 +0200 | [diff] [blame] | 1051 | err = super_setup_bdi_name(sb, "ceph-%ld", |
| 1052 | atomic_long_inc_return(&bdi_seq)); |
| 1053 | if (err) |
| 1054 | return err; |
| 1055 | |
Sage Weil | 83817e3 | 2011-08-04 08:03:44 -0700 | [diff] [blame] | 1056 | /* set ra_pages based on rasize mount option? */ |
Yan, Zheng | 4214fb1 | 2017-07-11 18:49:44 +0800 | [diff] [blame] | 1057 | sb->s_bdi->ra_pages = fsc->mount_options->rasize >> PAGE_SHIFT; |
Yehuda Sadeh | e985222 | 2011-07-22 11:12:28 -0700 | [diff] [blame] | 1058 | |
Yan, Zheng | aa18792 | 2017-07-11 15:56:09 +0800 | [diff] [blame] | 1059 | /* set io_pages based on max osd read size */ |
| 1060 | sb->s_bdi->io_pages = fsc->mount_options->rsize >> PAGE_SHIFT; |
Andreas Gerstmayr | 7c94ba2 | 2017-01-10 14:17:56 +0100 | [diff] [blame] | 1061 | |
Jan Kara | 09dc9fc | 2017-04-12 12:24:33 +0200 | [diff] [blame] | 1062 | return 0; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1065 | static struct dentry *ceph_mount(struct file_system_type *fs_type, |
| 1066 | int flags, const char *dev_name, void *data) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1067 | { |
| 1068 | struct super_block *sb; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1069 | struct ceph_fs_client *fsc; |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1070 | struct dentry *res; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1071 | int err; |
| 1072 | int (*compare_super)(struct super_block *, void *) = ceph_compare_super; |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1073 | struct ceph_mount_options *fsopt = NULL; |
| 1074 | struct ceph_options *opt = NULL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1075 | |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1076 | dout("ceph_mount\n"); |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 1077 | |
| 1078 | #ifdef CONFIG_CEPH_FS_POSIX_ACL |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1079 | flags |= SB_POSIXACL; |
Sage Weil | 45195e4 | 2014-02-16 10:05:29 -0800 | [diff] [blame] | 1080 | #endif |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 1081 | err = parse_mount_options(&fsopt, &opt, flags, data, dev_name); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1082 | if (err < 0) { |
| 1083 | res = ERR_PTR(err); |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 1084 | goto out_final; |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1085 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1086 | |
| 1087 | /* create client (which we may/may not use) */ |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1088 | fsc = create_fs_client(fsopt, opt); |
| 1089 | if (IS_ERR(fsc)) { |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1090 | res = ERR_CAST(fsc); |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 1091 | goto out_final; |
| 1092 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1093 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1094 | err = ceph_mdsc_init(fsc); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1095 | if (err < 0) { |
| 1096 | res = ERR_PTR(err); |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1097 | goto out; |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1098 | } |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1099 | |
| 1100 | if (ceph_test_opt(fsc->client, NOSHARE)) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1101 | compare_super = NULL; |
David Howells | 9249e17 | 2012-06-25 12:55:37 +0100 | [diff] [blame] | 1102 | sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1103 | if (IS_ERR(sb)) { |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1104 | res = ERR_CAST(sb); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1105 | goto out; |
| 1106 | } |
| 1107 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1108 | if (ceph_sb_to_client(sb) != fsc) { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1109 | destroy_fs_client(fsc); |
| 1110 | fsc = ceph_sb_to_client(sb); |
| 1111 | dout("get_sb got existing client %p\n", fsc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1112 | } else { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1113 | dout("get_sb using new client %p\n", fsc); |
Jan Kara | 09dc9fc | 2017-04-12 12:24:33 +0200 | [diff] [blame] | 1114 | err = ceph_setup_bdi(sb, fsc); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1115 | if (err < 0) { |
| 1116 | res = ERR_PTR(err); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1117 | goto out_splat; |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1118 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Yan, Zheng | 3f38495 | 2016-04-21 11:09:55 +0800 | [diff] [blame] | 1121 | res = ceph_real_mount(fsc); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1122 | if (IS_ERR(res)) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1123 | goto out_splat; |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1124 | dout("root %p inode %p ino %llx.%llx\n", res, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1125 | d_inode(res), ceph_vinop(d_inode(res))); |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1126 | return res; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1127 | |
| 1128 | out_splat: |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1129 | ceph_mdsc_close_sessions(fsc->mdsc); |
Al Viro | 3981f2e | 2010-03-21 19:22:29 -0400 | [diff] [blame] | 1130 | deactivate_locked_super(sb); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1131 | goto out_final; |
| 1132 | |
| 1133 | out: |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1134 | destroy_fs_client(fsc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1135 | out_final: |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1136 | dout("ceph_mount fail %ld\n", PTR_ERR(res)); |
| 1137 | return res; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static void ceph_kill_sb(struct super_block *s) |
| 1141 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1142 | struct ceph_fs_client *fsc = ceph_sb_to_client(s); |
Christoph Hellwig | e4d2750 | 2015-01-14 10:42:38 +0100 | [diff] [blame] | 1143 | dev_t dev = s->s_dev; |
| 1144 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1145 | dout("kill_sb %p\n", s); |
Christoph Hellwig | e4d2750 | 2015-01-14 10:42:38 +0100 | [diff] [blame] | 1146 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1147 | ceph_mdsc_pre_umount(fsc->mdsc); |
Yan, Zheng | a57d906 | 2018-05-18 16:05:51 +0800 | [diff] [blame] | 1148 | flush_fs_workqueues(fsc); |
| 1149 | |
Christoph Hellwig | e4d2750 | 2015-01-14 10:42:38 +0100 | [diff] [blame] | 1150 | generic_shutdown_super(s); |
Yan, Zheng | 62a65f3 | 2017-06-22 16:26:34 +0800 | [diff] [blame] | 1151 | |
| 1152 | fsc->client->extra_mon_dispatch = NULL; |
| 1153 | ceph_fs_debugfs_cleanup(fsc); |
| 1154 | |
Yan, Zheng | 1d8f836 | 2017-06-27 11:57:56 +0800 | [diff] [blame] | 1155 | ceph_fscache_unregister_fs(fsc); |
| 1156 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1157 | destroy_fs_client(fsc); |
Christoph Hellwig | e4d2750 | 2015-01-14 10:42:38 +0100 | [diff] [blame] | 1158 | free_anon_bdev(dev); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | static struct file_system_type ceph_fs_type = { |
| 1162 | .owner = THIS_MODULE, |
| 1163 | .name = "ceph", |
Al Viro | a7f9fb2 | 2010-07-26 16:17:55 +0400 | [diff] [blame] | 1164 | .mount = ceph_mount, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1165 | .kill_sb = ceph_kill_sb, |
| 1166 | .fs_flags = FS_RENAME_DOES_D_MOVE, |
| 1167 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 1168 | MODULE_ALIAS_FS("ceph"); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1169 | |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 1170 | int ceph_force_reconnect(struct super_block *sb) |
| 1171 | { |
| 1172 | struct ceph_fs_client *fsc = ceph_sb_to_client(sb); |
| 1173 | int err = 0; |
| 1174 | |
| 1175 | ceph_umount_begin(sb); |
| 1176 | |
| 1177 | /* Make sure all page caches get invalidated. |
| 1178 | * see remove_session_caps_cb() */ |
| 1179 | flush_workqueue(fsc->inode_wq); |
| 1180 | |
| 1181 | /* In case that we were blacklisted. This also reset |
| 1182 | * all mon/osd connections */ |
| 1183 | ceph_reset_client_addr(fsc->client); |
| 1184 | |
| 1185 | ceph_osdc_clear_abort_err(&fsc->client->osdc); |
Yan, Zheng | 131d7eb | 2019-07-25 20:16:47 +0800 | [diff] [blame] | 1186 | |
| 1187 | fsc->blacklisted = false; |
Yan, Zheng | d468e72 | 2019-07-25 20:16:44 +0800 | [diff] [blame] | 1188 | fsc->mount_state = CEPH_MOUNT_MOUNTED; |
| 1189 | |
| 1190 | if (sb->s_root) { |
| 1191 | err = __ceph_do_getattr(d_inode(sb->s_root), NULL, |
| 1192 | CEPH_STAT_CAP_INODE, true); |
| 1193 | } |
| 1194 | return err; |
| 1195 | } |
| 1196 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1197 | static int __init init_ceph(void) |
| 1198 | { |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1199 | int ret = init_caches(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1200 | if (ret) |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1201 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1202 | |
Yan, Zheng | eb13e83 | 2014-03-09 23:16:40 +0800 | [diff] [blame] | 1203 | ceph_flock_init(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1204 | ret = register_filesystem(&ceph_fs_type); |
| 1205 | if (ret) |
David Disseldorp | d0f191d | 2019-04-18 14:15:49 +0200 | [diff] [blame] | 1206 | goto out_caches; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1207 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 1208 | pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL); |
| 1209 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1210 | return 0; |
| 1211 | |
David Disseldorp | d0f191d | 2019-04-18 14:15:49 +0200 | [diff] [blame] | 1212 | out_caches: |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1213 | destroy_caches(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1214 | out: |
| 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | static void __exit exit_ceph(void) |
| 1219 | { |
| 1220 | dout("exit_ceph\n"); |
| 1221 | unregister_filesystem(&ceph_fs_type); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1222 | destroy_caches(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | module_init(init_ceph); |
| 1226 | module_exit(exit_ceph); |
| 1227 | |
| 1228 | MODULE_AUTHOR("Sage Weil <sage@newdream.net>"); |
| 1229 | MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>"); |
| 1230 | MODULE_AUTHOR("Patience Warnick <patience@newdream.net>"); |
| 1231 | MODULE_DESCRIPTION("Ceph filesystem for Linux"); |
| 1232 | MODULE_LICENSE("GPL"); |