vfs_super.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to:
  22. * Free Software Foundation
  23. * 51 Franklin Street, Fifth Floor
  24. * Boston, MA 02111-1301 USA
  25. *
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/config.h>
  29. #include <linux/module.h>
  30. #include <linux/errno.h>
  31. #include <linux/fs.h>
  32. #include <linux/file.h>
  33. #include <linux/stat.h>
  34. #include <linux/string.h>
  35. #include <linux/smp_lock.h>
  36. #include <linux/inet.h>
  37. #include <linux/pagemap.h>
  38. #include <linux/seq_file.h>
  39. #include <linux/mount.h>
  40. #include <linux/idr.h>
  41. #include "debug.h"
  42. #include "v9fs.h"
  43. #include "9p.h"
  44. #include "v9fs_vfs.h"
  45. #include "conv.h"
  46. #include "fid.h"
  47. static void v9fs_clear_inode(struct inode *);
  48. static struct super_operations v9fs_super_ops;
  49. /**
  50. * v9fs_clear_inode - release an inode
  51. * @inode: inode to release
  52. *
  53. */
  54. static void v9fs_clear_inode(struct inode *inode)
  55. {
  56. filemap_fdatawrite(inode->i_mapping);
  57. }
  58. /**
  59. * v9fs_set_super - set the superblock
  60. * @s: super block
  61. * @data: file system specific data
  62. *
  63. */
  64. static int v9fs_set_super(struct super_block *s, void *data)
  65. {
  66. s->s_fs_info = data;
  67. return set_anon_super(s, data);
  68. }
  69. /**
  70. * v9fs_fill_super - populate superblock with info
  71. * @sb: superblock
  72. * @v9ses: session information
  73. *
  74. */
  75. static void
  76. v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
  77. int flags)
  78. {
  79. sb->s_maxbytes = MAX_LFS_FILESIZE;
  80. sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
  81. sb->s_blocksize = 1 << sb->s_blocksize_bits;
  82. sb->s_magic = V9FS_MAGIC;
  83. sb->s_op = &v9fs_super_ops;
  84. sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
  85. MS_NODIRATIME | MS_NOATIME;
  86. }
  87. /**
  88. * v9fs_get_sb - mount a superblock
  89. * @fs_type: file system type
  90. * @flags: mount flags
  91. * @dev_name: device name that was mounted
  92. * @data: mount options
  93. *
  94. */
  95. static struct super_block *v9fs_get_sb(struct file_system_type
  96. *fs_type, int flags,
  97. const char *dev_name, void *data)
  98. {
  99. struct super_block *sb = NULL;
  100. struct v9fs_fcall *fcall = NULL;
  101. struct inode *inode = NULL;
  102. struct dentry *root = NULL;
  103. struct v9fs_session_info *v9ses = NULL;
  104. struct v9fs_fid *root_fid = NULL;
  105. int mode = S_IRWXUGO | S_ISVTX;
  106. uid_t uid = current->fsuid;
  107. gid_t gid = current->fsgid;
  108. int stat_result = 0;
  109. int newfid = 0;
  110. int retval = 0;
  111. dprintk(DEBUG_VFS, " \n");
  112. v9ses = kcalloc(1, sizeof(struct v9fs_session_info), GFP_KERNEL);
  113. if (!v9ses)
  114. return ERR_PTR(-ENOMEM);
  115. if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) {
  116. dprintk(DEBUG_ERROR, "problem initiating session\n");
  117. retval = newfid;
  118. goto free_session;
  119. }
  120. sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
  121. v9fs_fill_super(sb, v9ses, flags);
  122. inode = v9fs_get_inode(sb, S_IFDIR | mode);
  123. if (IS_ERR(inode)) {
  124. retval = PTR_ERR(inode);
  125. goto put_back_sb;
  126. }
  127. inode->i_uid = uid;
  128. inode->i_gid = gid;
  129. root = d_alloc_root(inode);
  130. if (!root) {
  131. retval = -ENOMEM;
  132. goto release_inode;
  133. }
  134. sb->s_root = root;
  135. /* Setup the Root Inode */
  136. root_fid = v9fs_fid_create(root);
  137. if (root_fid == NULL) {
  138. retval = -ENOMEM;
  139. goto release_dentry;
  140. }
  141. root_fid->fidopen = 0;
  142. root_fid->v9ses = v9ses;
  143. stat_result = v9fs_t_stat(v9ses, newfid, &fcall);
  144. if (stat_result < 0) {
  145. dprintk(DEBUG_ERROR, "stat error\n");
  146. v9fs_t_clunk(v9ses, newfid, NULL);
  147. v9fs_put_idpool(newfid, &v9ses->fidpool);
  148. } else {
  149. root_fid->fid = newfid;
  150. root_fid->qid = fcall->params.rstat.stat->qid;
  151. root->d_inode->i_ino =
  152. v9fs_qid2ino(&fcall->params.rstat.stat->qid);
  153. v9fs_mistat2inode(fcall->params.rstat.stat, root->d_inode, sb);
  154. }
  155. kfree(fcall);
  156. if (stat_result < 0) {
  157. retval = stat_result;
  158. goto release_dentry;
  159. }
  160. return sb;
  161. release_dentry:
  162. dput(sb->s_root);
  163. release_inode:
  164. iput(inode);
  165. put_back_sb:
  166. up_write(&sb->s_umount);
  167. deactivate_super(sb);
  168. v9fs_session_close(v9ses);
  169. free_session:
  170. kfree(v9ses);
  171. return ERR_PTR(retval);
  172. }
  173. /**
  174. * v9fs_kill_super - Kill Superblock
  175. * @s: superblock
  176. *
  177. */
  178. static void v9fs_kill_super(struct super_block *s)
  179. {
  180. struct v9fs_session_info *v9ses = s->s_fs_info;
  181. dprintk(DEBUG_VFS, " %p\n", s);
  182. v9fs_dentry_release(s->s_root); /* clunk root */
  183. kill_anon_super(s);
  184. v9fs_session_close(v9ses);
  185. kfree(v9ses);
  186. dprintk(DEBUG_VFS, "exiting kill_super\n");
  187. }
  188. /**
  189. * v9fs_show_options - Show mount options in /proc/mounts
  190. * @m: seq_file to write to
  191. * @mnt: mount descriptor
  192. *
  193. */
  194. static int v9fs_show_options(struct seq_file *m, struct vfsmount *mnt)
  195. {
  196. struct v9fs_session_info *v9ses = mnt->mnt_sb->s_fs_info;
  197. if (v9ses->debug != 0)
  198. seq_printf(m, ",debug=%u", v9ses->debug);
  199. if (v9ses->port != V9FS_PORT)
  200. seq_printf(m, ",port=%u", v9ses->port);
  201. if (v9ses->maxdata != 9000)
  202. seq_printf(m, ",msize=%u", v9ses->maxdata);
  203. if (v9ses->afid != ~0)
  204. seq_printf(m, ",afid=%u", v9ses->afid);
  205. if (v9ses->proto == PROTO_UNIX)
  206. seq_puts(m, ",proto=unix");
  207. if (v9ses->extended == 0)
  208. seq_puts(m, ",noextend");
  209. if (v9ses->nodev == 1)
  210. seq_puts(m, ",nodevmap");
  211. seq_printf(m, ",name=%s", v9ses->name);
  212. seq_printf(m, ",aname=%s", v9ses->remotename);
  213. seq_printf(m, ",uid=%u", v9ses->uid);
  214. seq_printf(m, ",gid=%u", v9ses->gid);
  215. return 0;
  216. }
  217. static void
  218. v9fs_umount_begin(struct super_block *sb)
  219. {
  220. struct v9fs_session_info *v9ses = sb->s_fs_info;
  221. v9fs_session_cancel(v9ses);
  222. }
  223. static struct super_operations v9fs_super_ops = {
  224. .statfs = simple_statfs,
  225. .clear_inode = v9fs_clear_inode,
  226. .show_options = v9fs_show_options,
  227. .umount_begin = v9fs_umount_begin,
  228. };
  229. struct file_system_type v9fs_fs_type = {
  230. .name = "9P",
  231. .get_sb = v9fs_get_sb,
  232. .kill_sb = v9fs_kill_super,
  233. .owner = THIS_MODULE,
  234. };