vfs_super.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * linux/fs/9p/vfs_super.c
  3. *
  4. * This file contians superblock ops for 9P2000. It is intended that
  5. * you mount this file system on directories.
  6. *
  7. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  8. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to:
  21. * Free Software Foundation
  22. * 51 Franklin Street, Fifth Floor
  23. * Boston, MA 02111-1301 USA
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/errno.h>
  29. #include <linux/fs.h>
  30. #include <linux/file.h>
  31. #include <linux/stat.h>
  32. #include <linux/string.h>
  33. #include <linux/inet.h>
  34. #include <linux/pagemap.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/mount.h>
  37. #include <linux/idr.h>
  38. #include <linux/sched.h>
  39. #include <linux/slab.h>
  40. #include <linux/statfs.h>
  41. #include <linux/magic.h>
  42. #include <net/9p/9p.h>
  43. #include <net/9p/client.h>
  44. #include "v9fs.h"
  45. #include "v9fs_vfs.h"
  46. #include "fid.h"
  47. #include "xattr.h"
  48. #include "acl.h"
  49. static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl;
  50. /**
  51. * v9fs_set_super - set the superblock
  52. * @s: super block
  53. * @data: file system specific data
  54. *
  55. */
  56. static int v9fs_set_super(struct super_block *s, void *data)
  57. {
  58. s->s_fs_info = data;
  59. return set_anon_super(s, data);
  60. }
  61. /**
  62. * v9fs_fill_super - populate superblock with info
  63. * @sb: superblock
  64. * @v9ses: session information
  65. * @flags: flags propagated from v9fs_mount()
  66. *
  67. */
  68. static void
  69. v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
  70. int flags, void *data)
  71. {
  72. sb->s_maxbytes = MAX_LFS_FILESIZE;
  73. sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
  74. sb->s_blocksize = 1 << sb->s_blocksize_bits;
  75. sb->s_magic = V9FS_MAGIC;
  76. if (v9fs_proto_dotl(v9ses)) {
  77. sb->s_op = &v9fs_super_ops_dotl;
  78. sb->s_xattr = v9fs_xattr_handlers;
  79. } else
  80. sb->s_op = &v9fs_super_ops;
  81. sb->s_bdi = &v9ses->bdi;
  82. if (v9ses->cache)
  83. sb->s_bdi->ra_pages = (VM_MAX_READAHEAD * 1024)/PAGE_CACHE_SIZE;
  84. sb->s_flags = flags | MS_ACTIVE | MS_DIRSYNC | MS_NOATIME;
  85. if (!v9ses->cache)
  86. sb->s_flags |= MS_SYNCHRONOUS;
  87. #ifdef CONFIG_9P_FS_POSIX_ACL
  88. if ((v9ses->flags & V9FS_ACL_MASK) == V9FS_POSIX_ACL)
  89. sb->s_flags |= MS_POSIXACL;
  90. #endif
  91. save_mount_options(sb, data);
  92. }
  93. /**
  94. * v9fs_mount - mount a superblock
  95. * @fs_type: file system type
  96. * @flags: mount flags
  97. * @dev_name: device name that was mounted
  98. * @data: mount options
  99. *
  100. */
  101. static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
  102. const char *dev_name, void *data)
  103. {
  104. struct super_block *sb = NULL;
  105. struct inode *inode = NULL;
  106. struct dentry *root = NULL;
  107. struct v9fs_session_info *v9ses = NULL;
  108. int mode = S_IRWXUGO | S_ISVTX;
  109. struct p9_fid *fid;
  110. int retval = 0;
  111. P9_DPRINTK(P9_DEBUG_VFS, " \n");
  112. v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
  113. if (!v9ses)
  114. return ERR_PTR(-ENOMEM);
  115. fid = v9fs_session_init(v9ses, dev_name, data);
  116. if (IS_ERR(fid)) {
  117. retval = PTR_ERR(fid);
  118. /*
  119. * we need to call session_close to tear down some
  120. * of the data structure setup by session_init
  121. */
  122. goto close_session;
  123. }
  124. sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
  125. if (IS_ERR(sb)) {
  126. retval = PTR_ERR(sb);
  127. goto clunk_fid;
  128. }
  129. v9fs_fill_super(sb, v9ses, flags, data);
  130. if (v9ses->cache)
  131. sb->s_d_op = &v9fs_cached_dentry_operations;
  132. else
  133. sb->s_d_op = &v9fs_dentry_operations;
  134. inode = v9fs_get_inode(sb, S_IFDIR | mode);
  135. if (IS_ERR(inode)) {
  136. retval = PTR_ERR(inode);
  137. goto release_sb;
  138. }
  139. root = d_alloc_root(inode);
  140. if (!root) {
  141. iput(inode);
  142. retval = -ENOMEM;
  143. goto release_sb;
  144. }
  145. sb->s_root = root;
  146. if (v9fs_proto_dotl(v9ses)) {
  147. struct p9_stat_dotl *st = NULL;
  148. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  149. if (IS_ERR(st)) {
  150. retval = PTR_ERR(st);
  151. goto release_sb;
  152. }
  153. root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
  154. v9fs_stat2inode_dotl(st, root->d_inode);
  155. kfree(st);
  156. } else {
  157. struct p9_wstat *st = NULL;
  158. st = p9_client_stat(fid);
  159. if (IS_ERR(st)) {
  160. retval = PTR_ERR(st);
  161. goto release_sb;
  162. }
  163. root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
  164. v9fs_stat2inode(st, root->d_inode, sb);
  165. p9stat_free(st);
  166. kfree(st);
  167. }
  168. v9fs_fid_add(root, fid);
  169. retval = v9fs_get_acl(inode, fid);
  170. if (retval)
  171. goto release_sb;
  172. /*
  173. * Add the root fid to session info. This is used
  174. * for file system sync. We want a cloned fid here
  175. * so that we can do a sync_filesystem after a
  176. * shrink_dcache_for_umount
  177. */
  178. v9ses->root_fid = v9fs_fid_clone(root);
  179. if (IS_ERR(v9ses->root_fid)) {
  180. retval = PTR_ERR(v9ses->root_fid);
  181. goto release_sb;
  182. }
  183. P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n");
  184. return dget(sb->s_root);
  185. clunk_fid:
  186. p9_client_clunk(fid);
  187. close_session:
  188. v9fs_session_close(v9ses);
  189. kfree(v9ses);
  190. return ERR_PTR(retval);
  191. release_sb:
  192. /*
  193. * we will do the session_close and root dentry
  194. * release in the below call.
  195. */
  196. deactivate_locked_super(sb);
  197. return ERR_PTR(retval);
  198. }
  199. /**
  200. * v9fs_kill_super - Kill Superblock
  201. * @s: superblock
  202. *
  203. */
  204. static void v9fs_kill_super(struct super_block *s)
  205. {
  206. struct v9fs_session_info *v9ses = s->s_fs_info;
  207. P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s);
  208. kill_anon_super(s);
  209. p9_client_clunk(v9ses->root_fid);
  210. v9fs_session_cancel(v9ses);
  211. v9fs_session_close(v9ses);
  212. kfree(v9ses);
  213. s->s_fs_info = NULL;
  214. P9_DPRINTK(P9_DEBUG_VFS, "exiting kill_super\n");
  215. }
  216. static void
  217. v9fs_umount_begin(struct super_block *sb)
  218. {
  219. struct v9fs_session_info *v9ses;
  220. v9ses = sb->s_fs_info;
  221. v9fs_session_begin_cancel(v9ses);
  222. }
  223. static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf)
  224. {
  225. struct v9fs_session_info *v9ses;
  226. struct p9_fid *fid;
  227. struct p9_rstatfs rs;
  228. int res;
  229. fid = v9fs_fid_lookup(dentry);
  230. if (IS_ERR(fid)) {
  231. res = PTR_ERR(fid);
  232. goto done;
  233. }
  234. v9ses = v9fs_dentry2v9ses(dentry);
  235. if (v9fs_proto_dotl(v9ses)) {
  236. res = p9_client_statfs(fid, &rs);
  237. if (res == 0) {
  238. buf->f_type = V9FS_MAGIC;
  239. buf->f_bsize = rs.bsize;
  240. buf->f_blocks = rs.blocks;
  241. buf->f_bfree = rs.bfree;
  242. buf->f_bavail = rs.bavail;
  243. buf->f_files = rs.files;
  244. buf->f_ffree = rs.ffree;
  245. buf->f_fsid.val[0] = rs.fsid & 0xFFFFFFFFUL;
  246. buf->f_fsid.val[1] = (rs.fsid >> 32) & 0xFFFFFFFFUL;
  247. buf->f_namelen = rs.namelen;
  248. }
  249. if (res != -ENOSYS)
  250. goto done;
  251. }
  252. res = simple_statfs(dentry, buf);
  253. done:
  254. return res;
  255. }
  256. static int v9fs_sync_fs(struct super_block *sb, int wait)
  257. {
  258. struct v9fs_session_info *v9ses = sb->s_fs_info;
  259. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_sync_fs: super_block %p\n", sb);
  260. return p9_client_sync_fs(v9ses->root_fid);
  261. }
  262. static int v9fs_drop_inode(struct inode *inode)
  263. {
  264. struct v9fs_session_info *v9ses;
  265. v9ses = v9fs_inode2v9ses(inode);
  266. if (v9ses->cache)
  267. return generic_drop_inode(inode);
  268. /*
  269. * in case of non cached mode always drop the
  270. * the inode because we want the inode attribute
  271. * to always match that on the server.
  272. */
  273. return 1;
  274. }
  275. static const struct super_operations v9fs_super_ops = {
  276. .alloc_inode = v9fs_alloc_inode,
  277. .destroy_inode = v9fs_destroy_inode,
  278. .statfs = simple_statfs,
  279. .evict_inode = v9fs_evict_inode,
  280. .show_options = generic_show_options,
  281. .umount_begin = v9fs_umount_begin,
  282. };
  283. static const struct super_operations v9fs_super_ops_dotl = {
  284. .alloc_inode = v9fs_alloc_inode,
  285. .destroy_inode = v9fs_destroy_inode,
  286. .sync_fs = v9fs_sync_fs,
  287. .statfs = v9fs_statfs,
  288. .drop_inode = v9fs_drop_inode,
  289. .evict_inode = v9fs_evict_inode,
  290. .show_options = generic_show_options,
  291. .umount_begin = v9fs_umount_begin,
  292. };
  293. struct file_system_type v9fs_fs_type = {
  294. .name = "9p",
  295. .mount = v9fs_mount,
  296. .kill_sb = v9fs_kill_super,
  297. .owner = THIS_MODULE,
  298. .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT,
  299. };