vfs_super.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "fid.h"
  46. static void v9fs_clear_inode(struct inode *);
  47. static struct super_operations v9fs_super_ops;
  48. /**
  49. * v9fs_clear_inode - release an inode
  50. * @inode: inode to release
  51. *
  52. */
  53. static void v9fs_clear_inode(struct inode *inode)
  54. {
  55. filemap_fdatawrite(inode->i_mapping);
  56. }
  57. /**
  58. * v9fs_set_super - set the superblock
  59. * @s: super block
  60. * @data: file system specific data
  61. *
  62. */
  63. static int v9fs_set_super(struct super_block *s, void *data)
  64. {
  65. s->s_fs_info = data;
  66. return set_anon_super(s, data);
  67. }
  68. /**
  69. * v9fs_fill_super - populate superblock with info
  70. * @sb: superblock
  71. * @v9ses: session information
  72. *
  73. */
  74. static void
  75. v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
  76. int flags)
  77. {
  78. sb->s_maxbytes = MAX_LFS_FILESIZE;
  79. sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
  80. sb->s_blocksize = 1 << sb->s_blocksize_bits;
  81. sb->s_magic = V9FS_MAGIC;
  82. sb->s_op = &v9fs_super_ops;
  83. sb->s_flags = flags | MS_ACTIVE | MS_SYNCHRONOUS | MS_DIRSYNC |
  84. MS_NOATIME;
  85. }
  86. /**
  87. * v9fs_get_sb - mount a superblock
  88. * @fs_type: file system type
  89. * @flags: mount flags
  90. * @dev_name: device name that was mounted
  91. * @data: mount options
  92. *
  93. */
  94. static struct super_block *v9fs_get_sb(struct file_system_type
  95. *fs_type, int flags,
  96. const char *dev_name, void *data)
  97. {
  98. struct super_block *sb = NULL;
  99. struct v9fs_fcall *fcall = NULL;
  100. struct inode *inode = NULL;
  101. struct dentry *root = NULL;
  102. struct v9fs_session_info *v9ses = NULL;
  103. struct v9fs_fid *root_fid = NULL;
  104. int mode = S_IRWXUGO | S_ISVTX;
  105. uid_t uid = current->fsuid;
  106. gid_t gid = current->fsgid;
  107. int stat_result = 0;
  108. int newfid = 0;
  109. int retval = 0;
  110. dprintk(DEBUG_VFS, " \n");
  111. v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
  112. if (!v9ses)
  113. return ERR_PTR(-ENOMEM);
  114. if ((newfid = v9fs_session_init(v9ses, dev_name, data)) < 0) {
  115. dprintk(DEBUG_ERROR, "problem initiating session\n");
  116. kfree(v9ses);
  117. return ERR_PTR(newfid);
  118. }
  119. sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
  120. v9fs_fill_super(sb, v9ses, flags);
  121. inode = v9fs_get_inode(sb, S_IFDIR | mode);
  122. if (IS_ERR(inode)) {
  123. retval = PTR_ERR(inode);
  124. goto put_back_sb;
  125. }
  126. inode->i_uid = uid;
  127. inode->i_gid = gid;
  128. root = d_alloc_root(inode);
  129. if (!root) {
  130. retval = -ENOMEM;
  131. goto put_back_sb;
  132. }
  133. sb->s_root = root;
  134. stat_result = v9fs_t_stat(v9ses, newfid, &fcall);
  135. if (stat_result < 0) {
  136. dprintk(DEBUG_ERROR, "stat error\n");
  137. v9fs_t_clunk(v9ses, newfid);
  138. v9fs_put_idpool(newfid, &v9ses->fidpool);
  139. } else {
  140. /* Setup the Root Inode */
  141. root_fid = v9fs_fid_create(root, v9ses, newfid, 0);
  142. if (root_fid == NULL) {
  143. retval = -ENOMEM;
  144. goto put_back_sb;
  145. }
  146. root_fid->qid = fcall->params.rstat.stat.qid;
  147. root->d_inode->i_ino =
  148. v9fs_qid2ino(&fcall->params.rstat.stat.qid);
  149. v9fs_stat2inode(&fcall->params.rstat.stat, root->d_inode, sb);
  150. }
  151. kfree(fcall);
  152. if (stat_result < 0) {
  153. retval = stat_result;
  154. goto put_back_sb;
  155. }
  156. return sb;
  157. put_back_sb:
  158. /* deactivate_super calls v9fs_kill_super which will frees the rest */
  159. up_write(&sb->s_umount);
  160. deactivate_super(sb);
  161. return ERR_PTR(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. dprintk(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. dprintk(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. if (v9ses->debug != 0)
  188. seq_printf(m, ",debug=%u", v9ses->debug);
  189. if (v9ses->port != V9FS_PORT)
  190. seq_printf(m, ",port=%u", v9ses->port);
  191. if (v9ses->maxdata != 9000)
  192. seq_printf(m, ",msize=%u", v9ses->maxdata);
  193. if (v9ses->afid != ~0)
  194. seq_printf(m, ",afid=%u", v9ses->afid);
  195. if (v9ses->proto == PROTO_UNIX)
  196. seq_puts(m, ",proto=unix");
  197. if (v9ses->extended == 0)
  198. seq_puts(m, ",noextend");
  199. if (v9ses->nodev == 1)
  200. seq_puts(m, ",nodevmap");
  201. seq_printf(m, ",name=%s", v9ses->name);
  202. seq_printf(m, ",aname=%s", v9ses->remotename);
  203. seq_printf(m, ",uid=%u", v9ses->uid);
  204. seq_printf(m, ",gid=%u", v9ses->gid);
  205. return 0;
  206. }
  207. static void
  208. v9fs_umount_begin(struct super_block *sb)
  209. {
  210. struct v9fs_session_info *v9ses = sb->s_fs_info;
  211. v9fs_session_cancel(v9ses);
  212. }
  213. static struct super_operations v9fs_super_ops = {
  214. .statfs = simple_statfs,
  215. .clear_inode = v9fs_clear_inode,
  216. .show_options = v9fs_show_options,
  217. .umount_begin = v9fs_umount_begin,
  218. };
  219. struct file_system_type v9fs_fs_type = {
  220. .name = "9P",
  221. .get_sb = v9fs_get_sb,
  222. .kill_sb = v9fs_kill_super,
  223. .owner = THIS_MODULE,
  224. };