original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

997 lines
24 KiB

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
12 years ago
ceph: let path portion of mount "device" be optional A recent change to /sbin/mountall causes any trailing '/' character in the "device" (or fs_spec) field in /etc/fstab to be stripped. As a result, an entry for a ceph mount that intends to mount the root of the name space ends up with now path portion, and the ceph mount option processing code rejects this. That is, an entry in /etc/fstab like: cephserver:port:/ /mnt ceph defaults 0 0 provides to the ceph code just "cephserver:port:" as the "device," and that gets rejected. Although this is a bug in /sbin/mountall, we can have the ceph mount code support an empty/nonexistent path, interpreting it to mean the root of the name space. RFC 5952 offers recommendations for how to express IPv6 addresses, and recommends the usage found in RFC 3986 (which specifies the format for URI's) for representing both IPv4 and IPv6 addresses that include port numbers. (See in particular the definition of "authority" found in the Appendix of RFC 3986.) According to those standards, no host specification will ever contain a '/' character. As a result, it is sufficient to scan a provided "device" from an /etc/fstab entry for the first '/' character, and if it's found, treat that as the beginning of the path. If no '/' character is present, we can treat the entire string as the monitor host specification(s), and assume the path to be the root of the name space. We'll still require a ':' to separate the host portion from the (possibly empty) path portion. This means that we can more formally define how ceph will interpret the "device" it's provided when processing a mount request: "device" will look like: <server_spec>[,<server_spec>...]:[<path>] where <server_spec> is <ip>[:<port>] <path> is optional, but if present must begin with '/' This addresses http://tracker.newdream.net/issues/2919 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Dan Mick <dan.mick@inktank.com>
9 years ago
ceph: let path portion of mount "device" be optional A recent change to /sbin/mountall causes any trailing '/' character in the "device" (or fs_spec) field in /etc/fstab to be stripped. As a result, an entry for a ceph mount that intends to mount the root of the name space ends up with now path portion, and the ceph mount option processing code rejects this. That is, an entry in /etc/fstab like: cephserver:port:/ /mnt ceph defaults 0 0 provides to the ceph code just "cephserver:port:" as the "device," and that gets rejected. Although this is a bug in /sbin/mountall, we can have the ceph mount code support an empty/nonexistent path, interpreting it to mean the root of the name space. RFC 5952 offers recommendations for how to express IPv6 addresses, and recommends the usage found in RFC 3986 (which specifies the format for URI's) for representing both IPv4 and IPv6 addresses that include port numbers. (See in particular the definition of "authority" found in the Appendix of RFC 3986.) According to those standards, no host specification will ever contain a '/' character. As a result, it is sufficient to scan a provided "device" from an /etc/fstab entry for the first '/' character, and if it's found, treat that as the beginning of the path. If no '/' character is present, we can treat the entire string as the monitor host specification(s), and assume the path to be the root of the name space. We'll still require a ':' to separate the host portion from the (possibly empty) path portion. This means that we can more formally define how ceph will interpret the "device" it's provided when processing a mount request: "device" will look like: <server_spec>[,<server_spec>...]:[<path>] where <server_spec> is <ip>[:<port>] <path> is optional, but if present must begin with '/' This addresses http://tracker.newdream.net/issues/2919 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Dan Mick <dan.mick@inktank.com>
9 years ago
ceph: let path portion of mount "device" be optional A recent change to /sbin/mountall causes any trailing '/' character in the "device" (or fs_spec) field in /etc/fstab to be stripped. As a result, an entry for a ceph mount that intends to mount the root of the name space ends up with now path portion, and the ceph mount option processing code rejects this. That is, an entry in /etc/fstab like: cephserver:port:/ /mnt ceph defaults 0 0 provides to the ceph code just "cephserver:port:" as the "device," and that gets rejected. Although this is a bug in /sbin/mountall, we can have the ceph mount code support an empty/nonexistent path, interpreting it to mean the root of the name space. RFC 5952 offers recommendations for how to express IPv6 addresses, and recommends the usage found in RFC 3986 (which specifies the format for URI's) for representing both IPv4 and IPv6 addresses that include port numbers. (See in particular the definition of "authority" found in the Appendix of RFC 3986.) According to those standards, no host specification will ever contain a '/' character. As a result, it is sufficient to scan a provided "device" from an /etc/fstab entry for the first '/' character, and if it's found, treat that as the beginning of the path. If no '/' character is present, we can treat the entire string as the monitor host specification(s), and assume the path to be the root of the name space. We'll still require a ':' to separate the host portion from the (possibly empty) path portion. This means that we can more formally define how ceph will interpret the "device" it's provided when processing a mount request: "device" will look like: <server_spec>[,<server_spec>...]:[<path>] where <server_spec> is <ip>[:<port>] <path> is optional, but if present must begin with '/' This addresses http://tracker.newdream.net/issues/2919 Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Dan Mick <dan.mick@inktank.com>
9 years ago
fs: Limit sys_mount to only request filesystem modules. Modify the request_module to prefix the file system type with "fs-" and add aliases to all of the filesystems that can be built as modules to match. A common practice is to build all of the kernel code and leave code that is not commonly needed as modules, with the result that many users are exposed to any bug anywhere in the kernel. Looking for filesystems with a fs- prefix limits the pool of possible modules that can be loaded by mount to just filesystems trivially making things safer with no real cost. Using aliases means user space can control the policy of which filesystem modules are auto-loaded by editing /etc/modprobe.d/*.conf with blacklist and alias directives. Allowing simple, safe, well understood work-arounds to known problematic software. This also addresses a rare but unfortunate problem where the filesystem name is not the same as it's module name and module auto-loading would not work. While writing this patch I saw a handful of such cases. The most significant being autofs that lives in the module autofs4. This is relevant to user namespaces because we can reach the request module in get_fs_type() without having any special permissions, and people get uncomfortable when a user specified string (in this case the filesystem type) goes all of the way to request_module. After having looked at this issue I don't think there is any particular reason to perform any filtering or permission checks beyond making it clear in the module request that we want a filesystem module. The common pattern in the kernel is to call request_module() without regards to the users permissions. In general all a filesystem module does once loaded is call register_filesystem() and go to sleep. Which means there is not much attack surface exposed by loading a filesytem module unless the filesystem is mounted. In a user namespace filesystems are not mounted unless .fs_flags = FS_USERNS_MOUNT, which most filesystems do not set today. Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Reported-by: Kees Cook <keescook@google.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
9 years ago
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/backing-dev.h>
  3. #include <linux/ctype.h>
  4. #include <linux/fs.h>
  5. #include <linux/inet.h>
  6. #include <linux/in6.h>
  7. #include <linux/module.h>
  8. #include <linux/mount.h>
  9. #include <linux/parser.h>
  10. #include <linux/sched.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/slab.h>
  13. #include <linux/statfs.h>
  14. #include <linux/string.h>
  15. #include "super.h"
  16. #include "mds_client.h"
  17. #include <linux/ceph/ceph_features.h>
  18. #include <linux/ceph/decode.h>
  19. #include <linux/ceph/mon_client.h>
  20. #include <linux/ceph/auth.h>
  21. #include <linux/ceph/debugfs.h>
  22. /*
  23. * Ceph superblock operations
  24. *
  25. * Handle the basics of mounting, unmounting.
  26. */
  27. /*
  28. * super ops
  29. */
  30. static void ceph_put_super(struct super_block *s)
  31. {
  32. struct ceph_fs_client *fsc = ceph_sb_to_client(s);
  33. dout("put_super\n");
  34. ceph_mdsc_close_sessions(fsc->mdsc);
  35. /*
  36. * ensure we release the bdi before put_anon_super releases
  37. * the device name.
  38. */
  39. if (s->s_bdi == &fsc->backing_dev_info) {
  40. bdi_unregister(&fsc->backing_dev_info);
  41. s->s_bdi = NULL;
  42. }
  43. return;
  44. }
  45. static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
  46. {
  47. struct ceph_fs_client *fsc = ceph_inode_to_client(dentry->d_inode);
  48. struct ceph_monmap *monmap = fsc->client->monc.monmap;
  49. struct ceph_statfs st;
  50. u64 fsid;
  51. int err;
  52. dout("statfs\n");
  53. err = ceph_monc_do_statfs(&fsc->client->monc, &st);
  54. if (err < 0)
  55. return err;
  56. /* fill in kstatfs */
  57. buf->f_type = CEPH_SUPER_MAGIC; /* ?? */
  58. /*
  59. * express utilization in terms of large blocks to avoid
  60. * overflow on 32-bit machines.
  61. *
  62. * NOTE: for the time being, we make bsize == frsize to humor
  63. * not-yet-ancient versions of glibc that are broken.
  64. * Someday, we will probably want to report a real block
  65. * size... whatever that may mean for a network file system!
  66. */
  67. buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
  68. buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
  69. buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
  70. buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
  71. buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
  72. buf->f_files = le64_to_cpu(st.num_objects);
  73. buf->f_ffree = -1;
  74. buf->f_namelen = NAME_MAX;
  75. /* leave fsid little-endian, regardless of host endianness */
  76. fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
  77. buf->f_fsid.val[0] = fsid & 0xffffffff;
  78. buf->f_fsid.val[1] = fsid >> 32;
  79. return 0;
  80. }
  81. static int ceph_sync_fs(struct super_block *sb, int wait)
  82. {
  83. struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
  84. if (!wait) {
  85. dout("sync_fs (non-blocking)\n");
  86. ceph_flush_dirty_caps(fsc->mdsc);
  87. dout("sync_fs (non-blocking) done\n");
  88. return 0;
  89. }
  90. dout("sync_fs (blocking)\n");
  91. ceph_osdc_sync(&fsc->client->osdc);
  92. ceph_mdsc_sync(fsc->mdsc);
  93. dout("sync_fs (blocking) done\n");
  94. return 0;
  95. }
  96. /*
  97. * mount options
  98. */
  99. enum {
  100. Opt_wsize,
  101. Opt_rsize,
  102. Opt_rasize,
  103. Opt_caps_wanted_delay_min,
  104. Opt_caps_wanted_delay_max,
  105. Opt_cap_release_safety,
  106. Opt_readdir_max_entries,
  107. Opt_readdir_max_bytes,
  108. Opt_congestion_kb,
  109. Opt_last_int,
  110. /* int args above */
  111. Opt_snapdirname,
  112. Opt_last_string,
  113. /* string args above */
  114. Opt_dirstat,
  115. Opt_nodirstat,
  116. Opt_rbytes,
  117. Opt_norbytes,
  118. Opt_asyncreaddir,
  119. Opt_noasyncreaddir,
  120. Opt_dcache,
  121. Opt_nodcache,
  122. Opt_ino32,
  123. Opt_noino32,
  124. };
  125. static match_table_t fsopt_tokens = {
  126. {Opt_wsize, "wsize=%d"},
  127. {Opt_rsize, "rsize=%d"},
  128. {Opt_rasize, "rasize=%d"},
  129. {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"},
  130. {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"},
  131. {Opt_cap_release_safety, "cap_release_safety=%d"},
  132. {Opt_readdir_max_entries, "readdir_max_entries=%d"},
  133. {Opt_readdir_max_bytes, "readdir_max_bytes=%d"},
  134. {Opt_congestion_kb, "write_congestion_kb=%d"},
  135. /* int args above */
  136. {Opt_snapdirname, "snapdirname=%s"},
  137. /* string args above */
  138. {Opt_dirstat, "dirstat"},
  139. {Opt_nodirstat, "nodirstat"},
  140. {Opt_rbytes, "rbytes"},
  141. {Opt_norbytes, "norbytes"},
  142. {Opt_asyncreaddir, "asyncreaddir"},
  143. {Opt_noasyncreaddir, "noasyncreaddir"},
  144. {Opt_dcache, "dcache"},
  145. {Opt_nodcache, "nodcache"},
  146. {Opt_ino32, "ino32"},
  147. {Opt_noino32, "noino32"},
  148. {-1, NULL}
  149. };
  150. static int parse_fsopt_token(char *c, void *private)
  151. {
  152. struct ceph_mount_options *fsopt = private;
  153. substring_t argstr[MAX_OPT_ARGS];
  154. int token, intval, ret;
  155. token = match_token((char *)c, fsopt_tokens, argstr);
  156. if (token < 0)
  157. return -EINVAL;
  158. if (token < Opt_last_int) {
  159. ret = match_int(&argstr[0], &intval);
  160. if (ret < 0) {
  161. pr_err("bad mount option arg (not int) "
  162. "at '%s'\n", c);
  163. return ret;
  164. }
  165. dout("got int token %d val %d\n", token, intval);
  166. } else if (token > Opt_last_int && token < Opt_last_string) {
  167. dout("got string token %d val %s\n", token,
  168. argstr[0].from);
  169. } else {
  170. dout("got token %d\n", token);
  171. }
  172. switch (token) {
  173. case Opt_snapdirname:
  174. kfree(fsopt->snapdir_name);
  175. fsopt->snapdir_name = kstrndup(argstr[0].from,
  176. argstr[0].to-argstr[0].from,
  177. GFP_KERNEL);
  178. if (!fsopt->snapdir_name)
  179. return -ENOMEM;
  180. break;
  181. /* misc */
  182. case Opt_wsize:
  183. fsopt->wsize = intval;
  184. break;
  185. case Opt_rsize:
  186. fsopt->rsize = intval;
  187. break;
  188. case Opt_rasize:
  189. fsopt->rasize = intval;
  190. break;
  191. case Opt_caps_wanted_delay_min:
  192. fsopt->caps_wanted_delay_min = intval;
  193. break;
  194. case Opt_caps_wanted_delay_max:
  195. fsopt->caps_wanted_delay_max = intval;
  196. break;
  197. case Opt_readdir_max_entries:
  198. fsopt->max_readdir = intval;
  199. break;
  200. case Opt_readdir_max_bytes:
  201. fsopt->max_readdir_bytes = intval;
  202. break;
  203. case Opt_congestion_kb:
  204. fsopt->congestion_kb = intval;
  205. break;
  206. case Opt_dirstat:
  207. fsopt->flags |= CEPH_MOUNT_OPT_DIRSTAT;
  208. break;
  209. case Opt_nodirstat:
  210. fsopt->flags &= ~CEPH_MOUNT_OPT_DIRSTAT;
  211. break;
  212. case Opt_rbytes:
  213. fsopt->flags |= CEPH_MOUNT_OPT_RBYTES;
  214. break;
  215. case Opt_norbytes:
  216. fsopt->flags &= ~CEPH_MOUNT_OPT_RBYTES;
  217. break;
  218. case Opt_asyncreaddir:
  219. fsopt->flags &= ~CEPH_MOUNT_OPT_NOASYNCREADDIR;
  220. break;
  221. case Opt_noasyncreaddir:
  222. fsopt->flags |= CEPH_MOUNT_OPT_NOASYNCREADDIR;
  223. break;
  224. case Opt_dcache:
  225. fsopt->flags |= CEPH_MOUNT_OPT_DCACHE;
  226. break;
  227. case Opt_nodcache:
  228. fsopt->flags &= ~CEPH_MOUNT_OPT_DCACHE;
  229. break;
  230. case Opt_ino32:
  231. fsopt->flags |= CEPH_MOUNT_OPT_INO32;
  232. break;
  233. case Opt_noino32:
  234. fsopt->flags &= ~CEPH_MOUNT_OPT_INO32;
  235. break;
  236. default:
  237. BUG_ON(token);
  238. }
  239. return 0;
  240. }
  241. static void destroy_mount_options(struct ceph_mount_options *args)
  242. {
  243. dout("destroy_mount_options %p\n", args);
  244. kfree(args->snapdir_name);
  245. kfree(args);
  246. }
  247. static int strcmp_null(const char *s1, const char *s2)
  248. {
  249. if (!s1 && !s2)
  250. return 0;
  251. if (s1 && !s2)
  252. return -1;
  253. if (!s1 && s2)
  254. return 1;
  255. return strcmp(s1, s2);
  256. }
  257. static int compare_mount_options(struct ceph_mount_options *new_fsopt,
  258. struct ceph_options *new_opt,
  259. struct ceph_fs_client *fsc)
  260. {
  261. struct ceph_mount_options *fsopt1 = new_fsopt;
  262. struct ceph_mount_options *fsopt2 = fsc->mount_options;
  263. int ofs = offsetof(struct ceph_mount_options, snapdir_name);
  264. int ret;
  265. ret = memcmp(fsopt1, fsopt2, ofs);
  266. if (ret)
  267. return ret;
  268. ret = strcmp_null(fsopt1->snapdir_name, fsopt2->snapdir_name);
  269. if (ret)
  270. return ret;
  271. return ceph_compare_options(new_opt, fsc->client);
  272. }
  273. static int parse_mount_options(struct ceph_mount_options **pfsopt,
  274. struct ceph_options **popt,
  275. int flags, char *options,
  276. const char *dev_name,
  277. const char **path)
  278. {
  279. struct ceph_mount_options *fsopt;
  280. const char *dev_name_end;
  281. int err;
  282. if (!dev_name || !*dev_name)
  283. return -EINVAL;
  284. fsopt = kzalloc(sizeof(*fsopt), GFP_KERNEL);
  285. if (!fsopt)
  286. return -ENOMEM;
  287. dout("parse_mount_options %p, dev_name '%s'\n", fsopt, dev_name);
  288. fsopt->sb_flags = flags;
  289. fsopt->flags = CEPH_MOUNT_OPT_DEFAULT;
  290. fsopt->rsize = CEPH_RSIZE_DEFAULT;
  291. fsopt->rasize = CEPH_RASIZE_DEFAULT;
  292. fsopt->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL);
  293. fsopt->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT;
  294. fsopt->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT;
  295. fsopt->cap_release_safety = CEPH_CAP_RELEASE_SAFETY_DEFAULT;
  296. fsopt->max_readdir = CEPH_MAX_READDIR_DEFAULT;
  297. fsopt->max_readdir_bytes = CEPH_MAX_READDIR_BYTES_DEFAULT;
  298. fsopt->congestion_kb = default_congestion_kb();
  299. /*
  300. * Distinguish the server list from the path in "dev_name".
  301. * Internally we do not include the leading '/' in the path.
  302. *
  303. * "dev_name" will look like:
  304. * <server_spec>[,<server_spec>...]:[<path>]
  305. * where
  306. * <server_spec> is <ip>[:<port>]
  307. * <path> is optional, but if present must begin with '/'
  308. */
  309. dev_name_end = strchr(dev_name, '/');
  310. if (dev_name_end) {
  311. /* skip over leading '/' for path */
  312. *path = dev_name_end + 1;
  313. } else {
  314. /* path is empty */
  315. dev_name_end = dev_name + strlen(dev_name);
  316. *path = dev_name_end;
  317. }
  318. err = -EINVAL;
  319. dev_name_end--; /* back up to ':' separator */
  320. if (*dev_name_end != ':') {
  321. pr_err("device name is missing path (no : separator in %s)\n",
  322. dev_name);
  323. goto out;
  324. }
  325. dout("device name '%.*s'\n", (int)(dev_name_end - dev_name), dev_name);
  326. dout("server path '%s'\n", *path);
  327. *popt = ceph_parse_options(options, dev_name, dev_name_end,
  328. parse_fsopt_token, (void *)fsopt);
  329. if (IS_ERR(*popt)) {
  330. err = PTR_ERR(*popt);
  331. goto out;
  332. }
  333. /* success */
  334. *pfsopt = fsopt;
  335. return 0;
  336. out:
  337. destroy_mount_options(fsopt);
  338. return err;
  339. }
  340. /**
  341. * ceph_show_options - Show mount options in /proc/mounts
  342. * @m: seq_file to write to
  343. * @root: root of that (sub)tree
  344. */
  345. static int ceph_show_options(struct seq_file *m, struct dentry *root)
  346. {
  347. struct ceph_fs_client *fsc = ceph_sb_to_client(root->d_sb);
  348. struct ceph_mount_options *fsopt = fsc->mount_options;
  349. struct ceph_options *opt = fsc->client->options;
  350. if (opt->flags & CEPH_OPT_FSID)
  351. seq_printf(m, ",fsid=%pU", &opt->fsid);
  352. if (opt->flags & CEPH_OPT_NOSHARE)
  353. seq_puts(m, ",noshare");
  354. if (opt->flags & CEPH_OPT_NOCRC)
  355. seq_puts(m, ",nocrc");
  356. if (opt->name)
  357. seq_printf(m, ",name=%s", opt->name);
  358. if (opt->key)
  359. seq_puts(m, ",secret=<hidden>");
  360. if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
  361. seq_printf(m, ",mount_timeout=%d", opt->mount_timeout);
  362. if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
  363. seq_printf(m, ",osd_idle_ttl=%d", opt->osd_idle_ttl);
  364. if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
  365. seq_printf(m, ",osdkeepalivetimeout=%d",
  366. opt->osd_keepalive_timeout);
  367. if (fsopt->flags & CEPH_MOUNT_OPT_DIRSTAT)
  368. seq_puts(m, ",dirstat");
  369. if ((fsopt->flags & CEPH_MOUNT_OPT_RBYTES) == 0)
  370. seq_puts(m, ",norbytes");
  371. if (fsopt->flags & CEPH_MOUNT_OPT_NOASYNCREADDIR)
  372. seq_puts(m, ",noasyncreaddir");
  373. if (fsopt->flags & CEPH_MOUNT_OPT_DCACHE)
  374. seq_puts(m, ",dcache");
  375. else
  376. seq_puts(m, ",nodcache");
  377. if (fsopt->wsize)
  378. seq_printf(m, ",wsize=%d", fsopt->wsize);
  379. if (fsopt->rsize != CEPH_RSIZE_DEFAULT)
  380. seq_printf(m, ",rsize=%d", fsopt->rsize);
  381. if (fsopt->rasize != CEPH_RASIZE_DEFAULT)
  382. seq_printf(m, ",rasize=%d", fsopt->rasize);
  383. if (fsopt->congestion_kb != default_congestion_kb())
  384. seq_printf(m, ",write_congestion_kb=%d", fsopt->congestion_kb);
  385. if (fsopt->caps_wanted_delay_min != CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT)
  386. seq_printf(m, ",caps_wanted_delay_min=%d",
  387. fsopt->caps_wanted_delay_min);
  388. if (fsopt->caps_wanted_delay_max != CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT)
  389. seq_printf(m, ",caps_wanted_delay_max=%d",
  390. fsopt->caps_wanted_delay_max);
  391. if (fsopt->cap_release_safety != CEPH_CAP_RELEASE_SAFETY_DEFAULT)
  392. seq_printf(m, ",cap_release_safety=%d",
  393. fsopt->cap_release_safety);
  394. if (fsopt->max_readdir != CEPH_MAX_READDIR_DEFAULT)
  395. seq_printf(m, ",readdir_max_entries=%d", fsopt->max_readdir);
  396. if (fsopt->max_readdir_bytes != CEPH_MAX_READDIR_BYTES_DEFAULT)
  397. seq_printf(m, ",readdir_max_bytes=%d", fsopt->max_readdir_bytes);
  398. if (strcmp(fsopt->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT))
  399. seq_printf(m, ",snapdirname=%s", fsopt->snapdir_name);
  400. return 0;
  401. }
  402. /*
  403. * handle any mon messages the standard library doesn't understand.
  404. * return error if we don't either.
  405. */
  406. static int extra_mon_dispatch(struct ceph_client *client, struct ceph_msg *msg)
  407. {
  408. struct ceph_fs_client *fsc = client->private;
  409. int type = le16_to_cpu(msg->hdr.type);
  410. switch (type) {
  411. case CEPH_MSG_MDS_MAP:
  412. ceph_mdsc_handle_map(fsc->mdsc, msg);
  413. return 0;
  414. default:
  415. return -1;
  416. }
  417. }
  418. /*
  419. * create a new fs client
  420. */
  421. static struct ceph_fs_client *create_fs_client(struct ceph_mount_options *fsopt,
  422. struct ceph_options *opt)
  423. {
  424. struct ceph_fs_client *fsc;
  425. const unsigned supported_features =
  426. CEPH_FEATURE_FLOCK |
  427. CEPH_FEATURE_DIRLAYOUTHASH;
  428. const unsigned required_features = 0;
  429. int err = -ENOMEM;
  430. fsc = kzalloc(sizeof(*fsc), GFP_KERNEL);
  431. if (!fsc)
  432. return ERR_PTR(-ENOMEM);
  433. fsc->client = ceph_create_client(opt, fsc, supported_features,
  434. required_features);
  435. if (IS_ERR(fsc->client)) {
  436. err = PTR_ERR(fsc->client);
  437. goto fail;
  438. }
  439. fsc->client->extra_mon_dispatch = extra_mon_dispatch;
  440. fsc->client->monc.want_mdsmap = 1;
  441. fsc->mount_options = fsopt;
  442. fsc->sb = NULL;
  443. fsc->mount_state = CEPH_MOUNT_MOUNTING;
  444. atomic_long_set(&fsc->writeback_count, 0);
  445. err = bdi_init(&fsc->backing_dev_info);
  446. if (err < 0)
  447. goto fail_client;
  448. err = -ENOMEM;
  449. /*
  450. * The number of concurrent works can be high but they don't need
  451. * to be processed in parallel, limit concurrency.
  452. */
  453. fsc->wb_wq = alloc_workqueue("ceph-writeback", 0, 1);
  454. if (fsc->wb_wq == NULL)
  455. goto fail_bdi;
  456. fsc->pg_inv_wq = alloc_workqueue("ceph-pg-invalid", 0, 1);
  457. if (fsc->pg_inv_wq == NULL)
  458. goto fail_wb_wq;
  459. fsc->trunc_wq = alloc_workqueue("ceph-trunc", 0, 1);
  460. if (fsc->trunc_wq == NULL)
  461. goto fail_pg_inv_wq;
  462. /* set up mempools */
  463. err = -ENOMEM;
  464. fsc->wb_pagevec_pool = mempool_create_kmalloc_pool(10,
  465. fsc->mount_options->wsize >> PAGE_CACHE_SHIFT);
  466. if (!fsc->wb_pagevec_pool)
  467. goto fail_trunc_wq;
  468. /* caps */
  469. fsc->min_caps = fsopt->max_readdir;
  470. return fsc;
  471. fail_trunc_wq:
  472. destroy_workqueue(fsc->trunc_wq);
  473. fail_pg_inv_wq:
  474. destroy_workqueue(fsc->pg_inv_wq);
  475. fail_wb_wq:
  476. destroy_workqueue(fsc->wb_wq);
  477. fail_bdi:
  478. bdi_destroy(&fsc->backing_dev_info);
  479. fail_client:
  480. ceph_destroy_client(fsc->client);
  481. fail:
  482. kfree(fsc);
  483. return ERR_PTR(err);
  484. }
  485. static void destroy_fs_client(struct ceph_fs_client *fsc)
  486. {
  487. dout("destroy_fs_client %p\n", fsc);
  488. destroy_workqueue(fsc->wb_wq);
  489. destroy_workqueue(fsc->pg_inv_wq);
  490. destroy_workqueue(fsc->trunc_wq);
  491. bdi_destroy(&fsc->backing_dev_info);
  492. mempool_destroy(fsc->wb_pagevec_pool);
  493. destroy_mount_options(fsc->mount_options);
  494. ceph_fs_debugfs_cleanup(fsc);
  495. ceph_destroy_client(fsc->client);
  496. kfree(fsc);
  497. dout("destroy_fs_client %p done\n", fsc);
  498. }
  499. /*
  500. * caches
  501. */
  502. struct kmem_cache *ceph_inode_cachep;
  503. struct kmem_cache *ceph_cap_cachep;
  504. struct kmem_cache *ceph_dentry_cachep;
  505. struct kmem_cache *ceph_file_cachep;
  506. static void ceph_inode_init_once(void *foo)
  507. {
  508. struct ceph_inode_info *ci = foo;
  509. inode_init_once(&ci->vfs_inode);
  510. }
  511. static int __init init_caches(void)
  512. {
  513. ceph_inode_cachep = kmem_cache_create("ceph_inode_info",
  514. sizeof(struct ceph_inode_info),
  515. __alignof__(struct ceph_inode_info),
  516. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  517. ceph_inode_init_once);
  518. if (ceph_inode_cachep == NULL)
  519. return -ENOMEM;
  520. ceph_cap_cachep = KMEM_CACHE(ceph_cap,
  521. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
  522. if (ceph_cap_cachep == NULL)
  523. goto bad_cap;
  524. ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
  525. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
  526. if (ceph_dentry_cachep == NULL)
  527. goto bad_dentry;
  528. ceph_file_cachep = KMEM_CACHE(ceph_file_info,
  529. SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
  530. if (ceph_file_cachep == NULL)
  531. goto bad_file;
  532. return 0;
  533. bad_file:
  534. kmem_cache_destroy(ceph_dentry_cachep);
  535. bad_dentry:
  536. kmem_cache_destroy(ceph_cap_cachep);
  537. bad_cap:
  538. kmem_cache_destroy(ceph_inode_cachep);
  539. return -ENOMEM;
  540. }
  541. static void destroy_caches(void)
  542. {
  543. /*
  544. * Make sure all delayed rcu free inodes are flushed before we
  545. * destroy cache.
  546. */
  547. rcu_barrier();
  548. kmem_cache_destroy(ceph_inode_cachep);
  549. kmem_cache_destroy(ceph_cap_cachep);
  550. kmem_cache_destroy(ceph_dentry_cachep);
  551. kmem_cache_destroy(ceph_file_cachep);
  552. }
  553. /*
  554. * ceph_umount_begin - initiate forced umount. Tear down down the
  555. * mount, skipping steps that may hang while waiting for server(s).
  556. */
  557. static void ceph_umount_begin(struct super_block *sb)
  558. {
  559. struct ceph_fs_client *fsc = ceph_sb_to_client(sb);
  560. dout("ceph_umount_begin - starting forced umount\n");
  561. if (!fsc)
  562. return;
  563. fsc->mount_state = CEPH_MOUNT_SHUTDOWN;
  564. return;
  565. }
  566. static const struct super_operations ceph_super_ops = {
  567. .alloc_inode = ceph_alloc_inode,
  568. .destroy_inode = ceph_destroy_inode,
  569. .write_inode = ceph_write_inode,
  570. .sync_fs = ceph_sync_fs,
  571. .put_super = ceph_put_super,
  572. .show_options = ceph_show_options,
  573. .statfs = ceph_statfs,
  574. .umount_begin = ceph_umount_begin,
  575. };
  576. /*
  577. * Bootstrap mount by opening the root directory. Note the mount
  578. * @started time from caller, and time out if this takes too long.
  579. */
  580. static struct dentry *open_root_dentry(struct ceph_fs_client *fsc,
  581. const char *path,
  582. unsigned long started)
  583. {
  584. struct ceph_mds_client *mdsc = fsc->mdsc;
  585. struct ceph_mds_request *req = NULL;
  586. int err;
  587. struct dentry *root;
  588. /* open dir */
  589. dout("open_root_inode opening '%s'\n", path);
  590. req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS);
  591. if (IS_ERR(req))
  592. return ERR_CAST(req);
  593. req->r_path1 = kstrdup(path, GFP_NOFS);
  594. req->r_ino1.ino = CEPH_INO_ROOT;
  595. req->r_ino1.snap = CEPH_NOSNAP;
  596. req->r_started = started;
  597. req->r_timeout = fsc->client->options->mount_timeout * HZ;
  598. req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
  599. req->r_num_caps = 2;
  600. err = ceph_mdsc_do_request(mdsc, NULL, req);
  601. if (err == 0) {
  602. struct inode *inode = req->r_target_inode;
  603. req->r_target_inode = NULL;
  604. dout("open_root_inode success\n");
  605. if (ceph_ino(inode) == CEPH_INO_ROOT &&
  606. fsc->sb->s_root == NULL) {
  607. root = d_make_root(inode);
  608. if (!root) {
  609. root = ERR_PTR(-ENOMEM);
  610. goto out;
  611. }
  612. } else {
  613. root = d_obtain_alias(inode);
  614. }
  615. ceph_init_dentry(root);
  616. dout("open_root_inode success, root dentry is %p\n", root);
  617. } else {
  618. root = ERR_PTR(err);
  619. }
  620. out:
  621. ceph_mdsc_put_request(req);
  622. return root;
  623. }
  624. /*
  625. * mount: join the ceph cluster, and open root directory.
  626. */
  627. static struct dentry *ceph_real_mount(struct ceph_fs_client *fsc,
  628. const char *path)
  629. {
  630. int err;
  631. unsigned long started = jiffies; /* note the start time */
  632. struct dentry *root;
  633. int first = 0; /* first vfsmount for this super_block */
  634. dout("mount start\n");
  635. mutex_lock(&fsc->client->mount_mutex);
  636. err = __ceph_open_session(fsc->client, started);
  637. if (err < 0)
  638. goto out;
  639. dout("mount opening root\n");
  640. root = open_root_dentry(fsc, "", started);
  641. if (IS_ERR(root)) {
  642. err = PTR_ERR(root);
  643. goto out;
  644. }
  645. if (fsc->sb->s_root) {
  646. dput(root);
  647. } else {
  648. fsc->sb->s_root = root;
  649. first = 1;
  650. err = ceph_fs_debugfs_init(fsc);
  651. if (err < 0)
  652. goto fail;
  653. }
  654. if (path[0] == 0) {
  655. dget(root);
  656. } else {
  657. dout("mount opening base mountpoint\n");
  658. root = open_root_dentry(fsc, path, started);
  659. if (IS_ERR(root)) {
  660. err = PTR_ERR(root);
  661. goto fail;
  662. }
  663. }
  664. fsc->mount_state = CEPH_MOUNT_MOUNTED;
  665. dout("mount success\n");
  666. mutex_unlock(&fsc->client->mount_mutex);
  667. return root;
  668. out:
  669. mutex_unlock(&fsc->client->mount_mutex);
  670. return ERR_PTR(err);
  671. fail:
  672. if (first) {
  673. dput(fsc->sb->s_root);
  674. fsc->sb->s_root = NULL;
  675. }
  676. goto out;
  677. }
  678. static int ceph_set_super(struct super_block *s, void *data)
  679. {
  680. struct ceph_fs_client *fsc = data;
  681. int ret;
  682. dout("set_super %p data %p\n", s, data);
  683. s->s_flags = fsc->mount_options->sb_flags;
  684. s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */
  685. s->s_fs_info = fsc;
  686. fsc->sb = s;
  687. s->s_op = &ceph_super_ops;
  688. s->s_export_op = &ceph_export_ops;
  689. s->s_time_gran = 1000; /* 1000 ns == 1 us */
  690. ret = set_anon_super(s, NULL); /* what is that second arg for? */
  691. if (ret != 0)
  692. goto fail;
  693. return ret;
  694. fail:
  695. s->s_fs_info = NULL;
  696. fsc->sb = NULL;
  697. return ret;
  698. }
  699. /*
  700. * share superblock if same fs AND options
  701. */
  702. static int ceph_compare_super(struct super_block *sb, void *data)
  703. {
  704. struct ceph_fs_client *new = data;
  705. struct ceph_mount_options *fsopt = new->mount_options;
  706. struct ceph_options *opt = new->client->options;
  707. struct ceph_fs_client *other = ceph_sb_to_client(sb);
  708. dout("ceph_compare_super %p\n", sb);
  709. if (compare_mount_options(fsopt, opt, other)) {
  710. dout("monitor(s)/mount options don't match\n");
  711. return 0;
  712. }
  713. if ((opt->flags & CEPH_OPT_FSID) &&
  714. ceph_fsid_compare(&opt->fsid, &other->client->fsid)) {
  715. dout("fsid doesn't match\n");
  716. return 0;
  717. }
  718. if (fsopt->sb_flags != other->mount_options->sb_flags) {
  719. dout("flags differ\n");
  720. return 0;
  721. }
  722. return 1;
  723. }
  724. /*
  725. * construct our own bdi so we can control readahead, etc.
  726. */
  727. static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
  728. static int ceph_register_bdi(struct super_block *sb,
  729. struct ceph_fs_client *fsc)
  730. {
  731. int err;
  732. /* set ra_pages based on rasize mount option? */
  733. if (fsc->mount_options->rasize >= PAGE_CACHE_SIZE)
  734. fsc->backing_dev_info.ra_pages =
  735. (fsc->mount_options->rasize + PAGE_CACHE_SIZE - 1)
  736. >> PAGE_SHIFT;
  737. else
  738. fsc->backing_dev_info.ra_pages =
  739. default_backing_dev_info.ra_pages;
  740. err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
  741. atomic_long_inc_return(&bdi_seq));
  742. if (!err)
  743. sb->s_bdi = &fsc->backing_dev_info;
  744. return err;
  745. }
  746. static struct dentry *ceph_mount(struct file_system_type *fs_type,
  747. int flags, const char *dev_name, void *data)
  748. {
  749. struct super_block *sb;
  750. struct ceph_fs_client *fsc;
  751. struct dentry *res;
  752. int err;
  753. int (*compare_super)(struct super_block *, void *) = ceph_compare_super;
  754. const char *path = NULL;
  755. struct ceph_mount_options *fsopt = NULL;
  756. struct ceph_options *opt = NULL;
  757. dout("ceph_mount\n");
  758. err = parse_mount_options(&fsopt, &opt, flags, data, dev_name, &path);
  759. if (err < 0) {
  760. res = ERR_PTR(err);
  761. goto out_final;
  762. }
  763. /* create client (which we may/may not use) */
  764. fsc = create_fs_client(fsopt, opt);
  765. if (IS_ERR(fsc)) {
  766. res = ERR_CAST(fsc);
  767. destroy_mount_options(fsopt);
  768. ceph_destroy_options(opt);
  769. goto out_final;
  770. }
  771. err = ceph_mdsc_init(fsc);
  772. if (err < 0) {
  773. res = ERR_PTR(err);
  774. goto out;
  775. }
  776. if (ceph_test_opt(fsc->client, NOSHARE))
  777. compare_super = NULL;
  778. sb = sget(fs_type, compare_super, ceph_set_super, flags, fsc);
  779. if (IS_ERR(sb)) {
  780. res = ERR_CAST(sb);
  781. goto out;
  782. }
  783. if (ceph_sb_to_client(sb) != fsc) {
  784. ceph_mdsc_destroy(fsc);
  785. destroy_fs_client(fsc);
  786. fsc = ceph_sb_to_client(sb);
  787. dout("get_sb got existing client %p\n", fsc);
  788. } else {
  789. dout("get_sb using new client %p\n", fsc);
  790. err = ceph_register_bdi(sb, fsc);
  791. if (err < 0) {
  792. res = ERR_PTR(err);
  793. goto out_splat;
  794. }
  795. }
  796. res = ceph_real_mount(fsc, path);
  797. if (IS_ERR(res))
  798. goto out_splat;
  799. dout("root %p inode %p ino %llx.%llx\n", res,
  800. res->d_inode, ceph_vinop(res->d_inode));
  801. return res;
  802. out_splat:
  803. ceph_mdsc_close_sessions(fsc->mdsc);
  804. deactivate_locked_super(sb);
  805. goto out_final;
  806. out:
  807. ceph_mdsc_destroy(fsc);
  808. destroy_fs_client(fsc);
  809. out_final:
  810. dout("ceph_mount fail %ld\n", PTR_ERR(res));
  811. return res;
  812. }
  813. static void ceph_kill_sb(struct super_block *s)
  814. {
  815. struct ceph_fs_client *fsc = ceph_sb_to_client(s);
  816. dout("kill_sb %p\n", s);
  817. ceph_mdsc_pre_umount(fsc->mdsc);
  818. kill_anon_super(s); /* will call put_super after sb is r/o */
  819. ceph_mdsc_destroy(fsc);
  820. destroy_fs_client(fsc);
  821. }
  822. static struct file_system_type ceph_fs_type = {
  823. .owner = THIS_MODULE,
  824. .name = "ceph",
  825. .mount = ceph_mount,
  826. .kill_sb = ceph_kill_sb,
  827. .fs_flags = FS_RENAME_DOES_D_MOVE,
  828. };
  829. MODULE_ALIAS_FS("ceph");
  830. #define _STRINGIFY(x) #x
  831. #define STRINGIFY(x) _STRINGIFY(x)
  832. static int __init init_ceph(void)
  833. {
  834. int ret = init_caches();
  835. if (ret)
  836. goto out;
  837. ceph_xattr_init();
  838. ret = register_filesystem(&ceph_fs_type);
  839. if (ret)
  840. goto out_icache;
  841. pr_info("loaded (mds proto %d)\n", CEPH_MDSC_PROTOCOL);
  842. return 0;
  843. out_icache:
  844. ceph_xattr_exit();
  845. destroy_caches();
  846. out:
  847. return ret;
  848. }
  849. static void __exit exit_ceph(void)
  850. {
  851. dout("exit_ceph\n");
  852. unregister_filesystem(&ceph_fs_type);
  853. ceph_xattr_exit();
  854. destroy_caches();
  855. }
  856. module_init(init_ceph);
  857. module_exit(exit_ceph);
  858. MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
  859. MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
  860. MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
  861. MODULE_DESCRIPTION("Ceph filesystem for Linux");
  862. MODULE_LICENSE("GPL");