vfs_super.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 <net/9p/9p.h>
  42. #include <net/9p/client.h>
  43. #include "v9fs.h"
  44. #include "v9fs_vfs.h"
  45. #include "fid.h"
  46. static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl;
  47. /**
  48. * v9fs_set_super - set the superblock
  49. * @s: super block
  50. * @data: file system specific data
  51. *
  52. */
  53. static int v9fs_set_super(struct super_block *s, void *data)
  54. {
  55. s->s_fs_info = data;
  56. return set_anon_super(s, data);
  57. }
  58. /**
  59. * v9fs_fill_super - populate superblock with info
  60. * @sb: superblock
  61. * @v9ses: session information
  62. * @flags: flags propagated from v9fs_get_sb()
  63. *
  64. */
  65. static void
  66. v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
  67. int flags, void *data)
  68. {
  69. sb->s_maxbytes = MAX_LFS_FILESIZE;
  70. sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
  71. sb->s_blocksize = 1 << sb->s_blocksize_bits;
  72. sb->s_magic = V9FS_MAGIC;
  73. if (v9fs_proto_dotl(v9ses))
  74. sb->s_op = &v9fs_super_ops_dotl;
  75. else
  76. sb->s_op = &v9fs_super_ops;
  77. sb->s_bdi = &v9ses->bdi;
  78. sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
  79. MS_NOATIME;
  80. save_mount_options(sb, data);
  81. }
  82. /**
  83. * v9fs_get_sb - mount a superblock
  84. * @fs_type: file system type
  85. * @flags: mount flags
  86. * @dev_name: device name that was mounted
  87. * @data: mount options
  88. * @mnt: mountpoint record to be instantiated
  89. *
  90. */
  91. static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
  92. const char *dev_name, void *data,
  93. struct vfsmount *mnt)
  94. {
  95. struct super_block *sb = NULL;
  96. struct inode *inode = NULL;
  97. struct dentry *root = NULL;
  98. struct v9fs_session_info *v9ses = NULL;
  99. struct p9_wstat *st = NULL;
  100. int mode = S_IRWXUGO | S_ISVTX;
  101. struct p9_fid *fid;
  102. int retval = 0;
  103. P9_DPRINTK(P9_DEBUG_VFS, " \n");
  104. v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
  105. if (!v9ses)
  106. return -ENOMEM;
  107. fid = v9fs_session_init(v9ses, dev_name, data);
  108. if (IS_ERR(fid)) {
  109. retval = PTR_ERR(fid);
  110. goto close_session;
  111. }
  112. st = p9_client_stat(fid);
  113. if (IS_ERR(st)) {
  114. retval = PTR_ERR(st);
  115. goto clunk_fid;
  116. }
  117. sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
  118. if (IS_ERR(sb)) {
  119. retval = PTR_ERR(sb);
  120. goto free_stat;
  121. }
  122. v9fs_fill_super(sb, v9ses, flags, data);
  123. inode = v9fs_get_inode(sb, S_IFDIR | mode);
  124. if (IS_ERR(inode)) {
  125. retval = PTR_ERR(inode);
  126. goto release_sb;
  127. }
  128. root = d_alloc_root(inode);
  129. if (!root) {
  130. iput(inode);
  131. retval = -ENOMEM;
  132. goto release_sb;
  133. }
  134. sb->s_root = root;
  135. root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
  136. v9fs_stat2inode(st, root->d_inode, sb);
  137. v9fs_fid_add(root, fid);
  138. p9stat_free(st);
  139. kfree(st);
  140. P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n");
  141. simple_set_mnt(mnt, sb);
  142. return 0;
  143. free_stat:
  144. p9stat_free(st);
  145. kfree(st);
  146. clunk_fid:
  147. p9_client_clunk(fid);
  148. close_session:
  149. v9fs_session_close(v9ses);
  150. kfree(v9ses);
  151. return retval;
  152. release_sb:
  153. p9stat_free(st);
  154. kfree(st);
  155. deactivate_locked_super(sb);
  156. return retval;
  157. }
  158. /**
  159. * v9fs_kill_super - Kill Superblock
  160. * @s: superblock
  161. *
  162. */
  163. static void v9fs_kill_super(struct super_block *s)
  164. {
  165. struct v9fs_session_info *v9ses = s->s_fs_info;
  166. P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s);
  167. if (s->s_root)
  168. v9fs_dentry_release(s->s_root); /* clunk root */
  169. kill_anon_super(s);
  170. v9fs_session_cancel(v9ses);
  171. v9fs_session_close(v9ses);
  172. kfree(v9ses);
  173. s->s_fs_info = NULL;
  174. P9_DPRINTK(P9_DEBUG_VFS, "exiting kill_super\n");
  175. }
  176. static void
  177. v9fs_umount_begin(struct super_block *sb)
  178. {
  179. struct v9fs_session_info *v9ses;
  180. v9ses = sb->s_fs_info;
  181. v9fs_session_begin_cancel(v9ses);
  182. }
  183. static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf)
  184. {
  185. struct v9fs_session_info *v9ses;
  186. struct p9_fid *fid;
  187. struct p9_rstatfs rs;
  188. int res;
  189. fid = v9fs_fid_lookup(dentry);
  190. if (IS_ERR(fid)) {
  191. res = PTR_ERR(fid);
  192. goto done;
  193. }
  194. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  195. if (v9fs_proto_dotl(v9ses)) {
  196. res = p9_client_statfs(fid, &rs);
  197. if (res == 0) {
  198. buf->f_type = rs.type;
  199. buf->f_bsize = rs.bsize;
  200. buf->f_blocks = rs.blocks;
  201. buf->f_bfree = rs.bfree;
  202. buf->f_bavail = rs.bavail;
  203. buf->f_files = rs.files;
  204. buf->f_ffree = rs.ffree;
  205. buf->f_fsid.val[0] = rs.fsid & 0xFFFFFFFFUL;
  206. buf->f_fsid.val[1] = (rs.fsid >> 32) & 0xFFFFFFFFUL;
  207. buf->f_namelen = rs.namelen;
  208. }
  209. if (res != -ENOSYS)
  210. goto done;
  211. }
  212. res = simple_statfs(dentry, buf);
  213. done:
  214. return res;
  215. }
  216. static const struct super_operations v9fs_super_ops = {
  217. #ifdef CONFIG_9P_FSCACHE
  218. .alloc_inode = v9fs_alloc_inode,
  219. .destroy_inode = v9fs_destroy_inode,
  220. #endif
  221. .statfs = simple_statfs,
  222. .clear_inode = v9fs_clear_inode,
  223. .show_options = generic_show_options,
  224. .umount_begin = v9fs_umount_begin,
  225. };
  226. static const struct super_operations v9fs_super_ops_dotl = {
  227. #ifdef CONFIG_9P_FSCACHE
  228. .alloc_inode = v9fs_alloc_inode,
  229. .destroy_inode = v9fs_destroy_inode,
  230. #endif
  231. .statfs = v9fs_statfs,
  232. .clear_inode = v9fs_clear_inode,
  233. .show_options = generic_show_options,
  234. .umount_begin = v9fs_umount_begin,
  235. };
  236. struct file_system_type v9fs_fs_type = {
  237. .name = "9p",
  238. .get_sb = v9fs_get_sb,
  239. .kill_sb = v9fs_kill_super,
  240. .owner = THIS_MODULE,
  241. };