vfs_super.c 5.0 KB

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