vfs_super.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 <net/9p/9p.h>
  40. #include <net/9p/client.h>
  41. #include "v9fs.h"
  42. #include "v9fs_vfs.h"
  43. #include "fid.h"
  44. static void v9fs_clear_inode(struct inode *);
  45. static const struct super_operations v9fs_super_ops;
  46. /**
  47. * v9fs_clear_inode - release an inode
  48. * @inode: inode to release
  49. *
  50. */
  51. static void v9fs_clear_inode(struct inode *inode)
  52. {
  53. filemap_fdatawrite(inode->i_mapping);
  54. }
  55. /**
  56. * v9fs_set_super - set the superblock
  57. * @s: super block
  58. * @data: file system specific data
  59. *
  60. */
  61. static int v9fs_set_super(struct super_block *s, void *data)
  62. {
  63. s->s_fs_info = data;
  64. return set_anon_super(s, data);
  65. }
  66. /**
  67. * v9fs_fill_super - populate superblock with info
  68. * @sb: superblock
  69. * @v9ses: session information
  70. *
  71. */
  72. static void
  73. v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
  74. int flags)
  75. {
  76. sb->s_maxbytes = MAX_LFS_FILESIZE;
  77. sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
  78. sb->s_blocksize = 1 << sb->s_blocksize_bits;
  79. sb->s_magic = V9FS_MAGIC;
  80. sb->s_op = &v9fs_super_ops;
  81. sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
  82. MS_NOATIME;
  83. }
  84. /**
  85. * v9fs_get_sb - mount a superblock
  86. * @fs_type: file system type
  87. * @flags: mount flags
  88. * @dev_name: device name that was mounted
  89. * @data: mount options
  90. * @mnt: mountpoint record to be instantiated
  91. *
  92. */
  93. static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
  94. const char *dev_name, void *data,
  95. struct vfsmount *mnt)
  96. {
  97. struct super_block *sb = NULL;
  98. struct inode *inode = NULL;
  99. struct dentry *root = NULL;
  100. struct v9fs_session_info *v9ses = NULL;
  101. struct p9_stat *st = NULL;
  102. int mode = S_IRWXUGO | S_ISVTX;
  103. uid_t uid = current->fsuid;
  104. gid_t gid = current->fsgid;
  105. struct p9_fid *fid;
  106. int retval = 0;
  107. P9_DPRINTK(P9_DEBUG_VFS, " \n");
  108. st = NULL;
  109. v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
  110. if (!v9ses)
  111. return -ENOMEM;
  112. fid = v9fs_session_init(v9ses, dev_name, data);
  113. if (IS_ERR(fid)) {
  114. retval = PTR_ERR(fid);
  115. fid = NULL;
  116. kfree(v9ses);
  117. v9ses = NULL;
  118. goto error;
  119. }
  120. st = p9_client_stat(fid);
  121. if (IS_ERR(st)) {
  122. retval = PTR_ERR(st);
  123. goto error;
  124. }
  125. sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
  126. if (IS_ERR(sb)) {
  127. retval = PTR_ERR(sb);
  128. goto error;
  129. }
  130. v9fs_fill_super(sb, v9ses, flags);
  131. inode = v9fs_get_inode(sb, S_IFDIR | mode);
  132. if (IS_ERR(inode)) {
  133. retval = PTR_ERR(inode);
  134. goto error;
  135. }
  136. inode->i_uid = uid;
  137. inode->i_gid = gid;
  138. root = d_alloc_root(inode);
  139. if (!root) {
  140. retval = -ENOMEM;
  141. goto error;
  142. }
  143. sb->s_root = root;
  144. root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
  145. v9fs_stat2inode(st, root->d_inode, sb);
  146. v9fs_fid_add(root, fid);
  147. kfree(st);
  148. return simple_set_mnt(mnt, sb);
  149. error:
  150. kfree(st);
  151. if (fid)
  152. p9_client_clunk(fid);
  153. if (v9ses) {
  154. v9fs_session_close(v9ses);
  155. kfree(v9ses);
  156. }
  157. if (sb) {
  158. up_write(&sb->s_umount);
  159. deactivate_super(sb);
  160. }
  161. return retval;
  162. }
  163. /**
  164. * v9fs_kill_super - Kill Superblock
  165. * @s: superblock
  166. *
  167. */
  168. static void v9fs_kill_super(struct super_block *s)
  169. {
  170. struct v9fs_session_info *v9ses = s->s_fs_info;
  171. P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s);
  172. v9fs_dentry_release(s->s_root); /* clunk root */
  173. kill_anon_super(s);
  174. v9fs_session_close(v9ses);
  175. kfree(v9ses);
  176. P9_DPRINTK(P9_DEBUG_VFS, "exiting kill_super\n");
  177. }
  178. /**
  179. * v9fs_show_options - Show mount options in /proc/mounts
  180. * @m: seq_file to write to
  181. * @mnt: mount descriptor
  182. *
  183. */
  184. static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
  185. {
  186. struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info;
  187. seq_printf(m, "%s", v9ses->options);
  188. return 0;
  189. }
  190. static void
  191. v9fs_umount_begin(struct vfsmount *vfsmnt, int flags)
  192. {
  193. struct v9fs_session_info *v9ses = vfsmnt->mnt_sb->s_fs_info;
  194. if (flags & MNT_FORCE)
  195. v9fs_session_cancel(v9ses);
  196. }
  197. static const struct super_operations v9fs_super_ops = {
  198. .statfs = simple_statfs,
  199. .clear_inode = v9fs_clear_inode,
  200. .show_options = v9fs_show_options,
  201. .umount_begin = v9fs_umount_begin,
  202. };
  203. struct file_system_type v9fs_fs_type = {
  204. .name = "9p",
  205. .get_sb = v9fs_get_sb,
  206. .kill_sb = v9fs_kill_super,
  207. .owner = THIS_MODULE,
  208. };