vfs_super.c 5.0 KB

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