vfs_inode_dotl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. /*
  2. * linux/fs/9p/vfs_inode_dotl.c
  3. *
  4. * This file contains vfs inode ops for the 9P2000.L protocol.
  5. *
  6. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  7. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to:
  20. * Free Software Foundation
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02111-1301 USA
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/errno.h>
  27. #include <linux/fs.h>
  28. #include <linux/file.h>
  29. #include <linux/pagemap.h>
  30. #include <linux/stat.h>
  31. #include <linux/string.h>
  32. #include <linux/inet.h>
  33. #include <linux/namei.h>
  34. #include <linux/idr.h>
  35. #include <linux/sched.h>
  36. #include <linux/slab.h>
  37. #include <linux/xattr.h>
  38. #include <linux/posix_acl.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. #include "cache.h"
  45. #include "xattr.h"
  46. #include "acl.h"
  47. static int
  48. v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
  49. dev_t rdev);
  50. /**
  51. * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
  52. * new file system object. This checks the S_ISGID to determine the owning
  53. * group of the new file system object.
  54. */
  55. static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
  56. {
  57. BUG_ON(dir_inode == NULL);
  58. if (dir_inode->i_mode & S_ISGID) {
  59. /* set_gid bit is set.*/
  60. return dir_inode->i_gid;
  61. }
  62. return current_fsgid();
  63. }
  64. /**
  65. * v9fs_dentry_from_dir_inode - helper function to get the dentry from
  66. * dir inode.
  67. *
  68. */
  69. static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
  70. {
  71. struct dentry *dentry;
  72. spin_lock(&inode->i_lock);
  73. /* Directory should have only one entry. */
  74. BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
  75. dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
  76. spin_unlock(&inode->i_lock);
  77. return dentry;
  78. }
  79. struct inode *
  80. v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
  81. struct super_block *sb)
  82. {
  83. struct inode *ret = NULL;
  84. int err;
  85. struct p9_stat_dotl *st;
  86. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  87. if (IS_ERR(st))
  88. return ERR_CAST(st);
  89. ret = v9fs_get_inode(sb, st->st_mode);
  90. if (IS_ERR(ret)) {
  91. err = PTR_ERR(ret);
  92. goto error;
  93. }
  94. v9fs_stat2inode_dotl(st, ret);
  95. ret->i_ino = v9fs_qid2ino(&st->qid);
  96. #ifdef CONFIG_9P_FSCACHE
  97. v9fs_vcookie_set_qid(ret, &st->qid);
  98. v9fs_cache_inode_get_cookie(ret);
  99. #endif
  100. err = v9fs_get_acl(ret, fid);
  101. if (err) {
  102. iput(ret);
  103. goto error;
  104. }
  105. kfree(st);
  106. return ret;
  107. error:
  108. kfree(st);
  109. return ERR_PTR(err);
  110. }
  111. /**
  112. * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
  113. * @dir: directory inode that is being created
  114. * @dentry: dentry that is being deleted
  115. * @mode: create permissions
  116. * @nd: path information
  117. *
  118. */
  119. static int
  120. v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
  121. struct nameidata *nd)
  122. {
  123. int err = 0;
  124. char *name = NULL;
  125. gid_t gid;
  126. int flags;
  127. mode_t mode;
  128. struct v9fs_session_info *v9ses;
  129. struct p9_fid *fid = NULL;
  130. struct p9_fid *dfid, *ofid;
  131. struct file *filp;
  132. struct p9_qid qid;
  133. struct inode *inode;
  134. struct posix_acl *pacl = NULL, *dacl = NULL;
  135. v9ses = v9fs_inode2v9ses(dir);
  136. if (nd && nd->flags & LOOKUP_OPEN)
  137. flags = nd->intent.open.flags - 1;
  138. else {
  139. /*
  140. * create call without LOOKUP_OPEN is due
  141. * to mknod of regular files. So use mknod
  142. * operation.
  143. */
  144. return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
  145. }
  146. name = (char *) dentry->d_name.name;
  147. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
  148. "mode:0x%x\n", name, flags, omode);
  149. dfid = v9fs_fid_lookup(dentry->d_parent);
  150. if (IS_ERR(dfid)) {
  151. err = PTR_ERR(dfid);
  152. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  153. return err;
  154. }
  155. /* clone a fid to use for creation */
  156. ofid = p9_client_walk(dfid, 0, NULL, 1);
  157. if (IS_ERR(ofid)) {
  158. err = PTR_ERR(ofid);
  159. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  160. return err;
  161. }
  162. gid = v9fs_get_fsgid_for_create(dir);
  163. mode = omode;
  164. /* Update mode based on ACL value */
  165. err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
  166. if (err) {
  167. P9_DPRINTK(P9_DEBUG_VFS,
  168. "Failed to get acl values in creat %d\n", err);
  169. goto error;
  170. }
  171. err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
  172. if (err < 0) {
  173. P9_DPRINTK(P9_DEBUG_VFS,
  174. "p9_client_open_dotl failed in creat %d\n",
  175. err);
  176. goto error;
  177. }
  178. /* instantiate inode and assign the unopened fid to the dentry */
  179. fid = p9_client_walk(dfid, 1, &name, 1);
  180. if (IS_ERR(fid)) {
  181. err = PTR_ERR(fid);
  182. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
  183. fid = NULL;
  184. goto error;
  185. }
  186. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  187. if (IS_ERR(inode)) {
  188. err = PTR_ERR(inode);
  189. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
  190. goto error;
  191. }
  192. d_instantiate(dentry, inode);
  193. err = v9fs_fid_add(dentry, fid);
  194. if (err < 0)
  195. goto error;
  196. /* Now set the ACL based on the default value */
  197. v9fs_set_create_acl(dentry, dacl, pacl);
  198. /* Since we are opening a file, assign the open fid to the file */
  199. filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
  200. if (IS_ERR(filp)) {
  201. p9_client_clunk(ofid);
  202. return PTR_ERR(filp);
  203. }
  204. filp->private_data = ofid;
  205. #ifdef CONFIG_9P_FSCACHE
  206. if (v9ses->cache)
  207. v9fs_cache_inode_set_cookie(inode, filp);
  208. #endif
  209. return 0;
  210. error:
  211. if (ofid)
  212. p9_client_clunk(ofid);
  213. if (fid)
  214. p9_client_clunk(fid);
  215. return err;
  216. }
  217. /**
  218. * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
  219. * @dir: inode that is being unlinked
  220. * @dentry: dentry that is being unlinked
  221. * @mode: mode for new directory
  222. *
  223. */
  224. static int v9fs_vfs_mkdir_dotl(struct inode *dir,
  225. struct dentry *dentry, int omode)
  226. {
  227. int err;
  228. struct v9fs_session_info *v9ses;
  229. struct p9_fid *fid = NULL, *dfid = NULL;
  230. gid_t gid;
  231. char *name;
  232. mode_t mode;
  233. struct inode *inode;
  234. struct p9_qid qid;
  235. struct dentry *dir_dentry;
  236. struct posix_acl *dacl = NULL, *pacl = NULL;
  237. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  238. err = 0;
  239. v9ses = v9fs_inode2v9ses(dir);
  240. omode |= S_IFDIR;
  241. if (dir->i_mode & S_ISGID)
  242. omode |= S_ISGID;
  243. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  244. dfid = v9fs_fid_lookup(dir_dentry);
  245. if (IS_ERR(dfid)) {
  246. err = PTR_ERR(dfid);
  247. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  248. dfid = NULL;
  249. goto error;
  250. }
  251. gid = v9fs_get_fsgid_for_create(dir);
  252. mode = omode;
  253. /* Update mode based on ACL value */
  254. err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
  255. if (err) {
  256. P9_DPRINTK(P9_DEBUG_VFS,
  257. "Failed to get acl values in mkdir %d\n", err);
  258. goto error;
  259. }
  260. name = (char *) dentry->d_name.name;
  261. err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
  262. if (err < 0)
  263. goto error;
  264. /* instantiate inode and assign the unopened fid to the dentry */
  265. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  266. fid = p9_client_walk(dfid, 1, &name, 1);
  267. if (IS_ERR(fid)) {
  268. err = PTR_ERR(fid);
  269. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  270. err);
  271. fid = NULL;
  272. goto error;
  273. }
  274. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  275. if (IS_ERR(inode)) {
  276. err = PTR_ERR(inode);
  277. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  278. err);
  279. goto error;
  280. }
  281. d_instantiate(dentry, inode);
  282. err = v9fs_fid_add(dentry, fid);
  283. if (err < 0)
  284. goto error;
  285. fid = NULL;
  286. } else {
  287. /*
  288. * Not in cached mode. No need to populate
  289. * inode with stat. We need to get an inode
  290. * so that we can set the acl with dentry
  291. */
  292. inode = v9fs_get_inode(dir->i_sb, mode);
  293. if (IS_ERR(inode)) {
  294. err = PTR_ERR(inode);
  295. goto error;
  296. }
  297. d_instantiate(dentry, inode);
  298. }
  299. /* Now set the ACL based on the default value */
  300. v9fs_set_create_acl(dentry, dacl, pacl);
  301. error:
  302. if (fid)
  303. p9_client_clunk(fid);
  304. return err;
  305. }
  306. static int
  307. v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
  308. struct kstat *stat)
  309. {
  310. int err;
  311. struct v9fs_session_info *v9ses;
  312. struct p9_fid *fid;
  313. struct p9_stat_dotl *st;
  314. P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
  315. err = -EPERM;
  316. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  317. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
  318. return simple_getattr(mnt, dentry, stat);
  319. fid = v9fs_fid_lookup(dentry);
  320. if (IS_ERR(fid))
  321. return PTR_ERR(fid);
  322. /* Ask for all the fields in stat structure. Server will return
  323. * whatever it supports
  324. */
  325. st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
  326. if (IS_ERR(st))
  327. return PTR_ERR(st);
  328. v9fs_stat2inode_dotl(st, dentry->d_inode);
  329. generic_fillattr(dentry->d_inode, stat);
  330. /* Change block size to what the server returned */
  331. stat->blksize = st->st_blksize;
  332. kfree(st);
  333. return 0;
  334. }
  335. /**
  336. * v9fs_vfs_setattr_dotl - set file metadata
  337. * @dentry: file whose metadata to set
  338. * @iattr: metadata assignment structure
  339. *
  340. */
  341. int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
  342. {
  343. int retval;
  344. struct v9fs_session_info *v9ses;
  345. struct p9_fid *fid;
  346. struct p9_iattr_dotl p9attr;
  347. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  348. retval = inode_change_ok(dentry->d_inode, iattr);
  349. if (retval)
  350. return retval;
  351. p9attr.valid = iattr->ia_valid;
  352. p9attr.mode = iattr->ia_mode;
  353. p9attr.uid = iattr->ia_uid;
  354. p9attr.gid = iattr->ia_gid;
  355. p9attr.size = iattr->ia_size;
  356. p9attr.atime_sec = iattr->ia_atime.tv_sec;
  357. p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
  358. p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
  359. p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
  360. retval = -EPERM;
  361. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  362. fid = v9fs_fid_lookup(dentry);
  363. if (IS_ERR(fid))
  364. return PTR_ERR(fid);
  365. retval = p9_client_setattr(fid, &p9attr);
  366. if (retval < 0)
  367. return retval;
  368. if ((iattr->ia_valid & ATTR_SIZE) &&
  369. iattr->ia_size != i_size_read(dentry->d_inode)) {
  370. retval = vmtruncate(dentry->d_inode, iattr->ia_size);
  371. if (retval)
  372. return retval;
  373. }
  374. setattr_copy(dentry->d_inode, iattr);
  375. mark_inode_dirty(dentry->d_inode);
  376. if (iattr->ia_valid & ATTR_MODE) {
  377. /* We also want to update ACL when we update mode bits */
  378. retval = v9fs_acl_chmod(dentry);
  379. if (retval < 0)
  380. return retval;
  381. }
  382. return 0;
  383. }
  384. /**
  385. * v9fs_stat2inode_dotl - populate an inode structure with stat info
  386. * @stat: stat structure
  387. * @inode: inode to populate
  388. * @sb: superblock of filesystem
  389. *
  390. */
  391. void
  392. v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
  393. {
  394. if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
  395. inode->i_atime.tv_sec = stat->st_atime_sec;
  396. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  397. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  398. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  399. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  400. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  401. inode->i_uid = stat->st_uid;
  402. inode->i_gid = stat->st_gid;
  403. inode->i_nlink = stat->st_nlink;
  404. inode->i_mode = stat->st_mode;
  405. inode->i_rdev = new_decode_dev(stat->st_rdev);
  406. if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
  407. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  408. i_size_write(inode, stat->st_size);
  409. inode->i_blocks = stat->st_blocks;
  410. } else {
  411. if (stat->st_result_mask & P9_STATS_ATIME) {
  412. inode->i_atime.tv_sec = stat->st_atime_sec;
  413. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  414. }
  415. if (stat->st_result_mask & P9_STATS_MTIME) {
  416. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  417. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  418. }
  419. if (stat->st_result_mask & P9_STATS_CTIME) {
  420. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  421. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  422. }
  423. if (stat->st_result_mask & P9_STATS_UID)
  424. inode->i_uid = stat->st_uid;
  425. if (stat->st_result_mask & P9_STATS_GID)
  426. inode->i_gid = stat->st_gid;
  427. if (stat->st_result_mask & P9_STATS_NLINK)
  428. inode->i_nlink = stat->st_nlink;
  429. if (stat->st_result_mask & P9_STATS_MODE) {
  430. inode->i_mode = stat->st_mode;
  431. if ((S_ISBLK(inode->i_mode)) ||
  432. (S_ISCHR(inode->i_mode)))
  433. init_special_inode(inode, inode->i_mode,
  434. inode->i_rdev);
  435. }
  436. if (stat->st_result_mask & P9_STATS_RDEV)
  437. inode->i_rdev = new_decode_dev(stat->st_rdev);
  438. if (stat->st_result_mask & P9_STATS_SIZE)
  439. i_size_write(inode, stat->st_size);
  440. if (stat->st_result_mask & P9_STATS_BLOCKS)
  441. inode->i_blocks = stat->st_blocks;
  442. }
  443. if (stat->st_result_mask & P9_STATS_GEN)
  444. inode->i_generation = stat->st_gen;
  445. /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
  446. * because the inode structure does not have fields for them.
  447. */
  448. }
  449. static int
  450. v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
  451. const char *symname)
  452. {
  453. struct v9fs_session_info *v9ses;
  454. struct p9_fid *dfid;
  455. struct p9_fid *fid = NULL;
  456. struct inode *inode;
  457. struct p9_qid qid;
  458. char *name;
  459. int err;
  460. gid_t gid;
  461. name = (char *) dentry->d_name.name;
  462. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
  463. dir->i_ino, name, symname);
  464. v9ses = v9fs_inode2v9ses(dir);
  465. dfid = v9fs_fid_lookup(dentry->d_parent);
  466. if (IS_ERR(dfid)) {
  467. err = PTR_ERR(dfid);
  468. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  469. return err;
  470. }
  471. gid = v9fs_get_fsgid_for_create(dir);
  472. /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
  473. err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
  474. if (err < 0) {
  475. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
  476. goto error;
  477. }
  478. if (v9ses->cache) {
  479. /* Now walk from the parent so we can get an unopened fid. */
  480. fid = p9_client_walk(dfid, 1, &name, 1);
  481. if (IS_ERR(fid)) {
  482. err = PTR_ERR(fid);
  483. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  484. err);
  485. fid = NULL;
  486. goto error;
  487. }
  488. /* instantiate inode and assign the unopened fid to dentry */
  489. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  490. if (IS_ERR(inode)) {
  491. err = PTR_ERR(inode);
  492. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  493. err);
  494. goto error;
  495. }
  496. d_instantiate(dentry, inode);
  497. err = v9fs_fid_add(dentry, fid);
  498. if (err < 0)
  499. goto error;
  500. fid = NULL;
  501. } else {
  502. /* Not in cached mode. No need to populate inode with stat */
  503. inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
  504. if (IS_ERR(inode)) {
  505. err = PTR_ERR(inode);
  506. goto error;
  507. }
  508. d_instantiate(dentry, inode);
  509. }
  510. error:
  511. if (fid)
  512. p9_client_clunk(fid);
  513. return err;
  514. }
  515. /**
  516. * v9fs_vfs_link_dotl - create a hardlink for dotl
  517. * @old_dentry: dentry for file to link to
  518. * @dir: inode destination for new link
  519. * @dentry: dentry for link
  520. *
  521. */
  522. static int
  523. v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
  524. struct dentry *dentry)
  525. {
  526. int err;
  527. struct p9_fid *dfid, *oldfid;
  528. char *name;
  529. struct v9fs_session_info *v9ses;
  530. struct dentry *dir_dentry;
  531. P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
  532. dir->i_ino, old_dentry->d_name.name,
  533. dentry->d_name.name);
  534. v9ses = v9fs_inode2v9ses(dir);
  535. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  536. dfid = v9fs_fid_lookup(dir_dentry);
  537. if (IS_ERR(dfid))
  538. return PTR_ERR(dfid);
  539. oldfid = v9fs_fid_lookup(old_dentry);
  540. if (IS_ERR(oldfid))
  541. return PTR_ERR(oldfid);
  542. name = (char *) dentry->d_name.name;
  543. err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
  544. if (err < 0) {
  545. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
  546. return err;
  547. }
  548. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  549. /* Get the latest stat info from server. */
  550. struct p9_fid *fid;
  551. struct p9_stat_dotl *st;
  552. fid = v9fs_fid_lookup(old_dentry);
  553. if (IS_ERR(fid))
  554. return PTR_ERR(fid);
  555. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  556. if (IS_ERR(st))
  557. return PTR_ERR(st);
  558. v9fs_stat2inode_dotl(st, old_dentry->d_inode);
  559. kfree(st);
  560. } else {
  561. /* Caching disabled. No need to get upto date stat info.
  562. * This dentry will be released immediately. So, just hold the
  563. * inode
  564. */
  565. ihold(old_dentry->d_inode);
  566. }
  567. d_instantiate(dentry, old_dentry->d_inode);
  568. return err;
  569. }
  570. /**
  571. * v9fs_vfs_mknod_dotl - create a special file
  572. * @dir: inode destination for new link
  573. * @dentry: dentry for file
  574. * @mode: mode for creation
  575. * @rdev: device associated with special file
  576. *
  577. */
  578. static int
  579. v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
  580. dev_t rdev)
  581. {
  582. int err;
  583. char *name;
  584. mode_t mode;
  585. struct v9fs_session_info *v9ses;
  586. struct p9_fid *fid = NULL, *dfid = NULL;
  587. struct inode *inode;
  588. gid_t gid;
  589. struct p9_qid qid;
  590. struct dentry *dir_dentry;
  591. struct posix_acl *dacl = NULL, *pacl = NULL;
  592. P9_DPRINTK(P9_DEBUG_VFS,
  593. " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
  594. dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
  595. if (!new_valid_dev(rdev))
  596. return -EINVAL;
  597. v9ses = v9fs_inode2v9ses(dir);
  598. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  599. dfid = v9fs_fid_lookup(dir_dentry);
  600. if (IS_ERR(dfid)) {
  601. err = PTR_ERR(dfid);
  602. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  603. dfid = NULL;
  604. goto error;
  605. }
  606. gid = v9fs_get_fsgid_for_create(dir);
  607. mode = omode;
  608. /* Update mode based on ACL value */
  609. err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
  610. if (err) {
  611. P9_DPRINTK(P9_DEBUG_VFS,
  612. "Failed to get acl values in mknod %d\n", err);
  613. goto error;
  614. }
  615. name = (char *) dentry->d_name.name;
  616. err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
  617. if (err < 0)
  618. goto error;
  619. /* instantiate inode and assign the unopened fid to the dentry */
  620. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  621. fid = p9_client_walk(dfid, 1, &name, 1);
  622. if (IS_ERR(fid)) {
  623. err = PTR_ERR(fid);
  624. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  625. err);
  626. fid = NULL;
  627. goto error;
  628. }
  629. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  630. if (IS_ERR(inode)) {
  631. err = PTR_ERR(inode);
  632. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  633. err);
  634. goto error;
  635. }
  636. d_instantiate(dentry, inode);
  637. err = v9fs_fid_add(dentry, fid);
  638. if (err < 0)
  639. goto error;
  640. fid = NULL;
  641. } else {
  642. /*
  643. * Not in cached mode. No need to populate inode with stat.
  644. * socket syscall returns a fd, so we need instantiate
  645. */
  646. inode = v9fs_get_inode(dir->i_sb, mode);
  647. if (IS_ERR(inode)) {
  648. err = PTR_ERR(inode);
  649. goto error;
  650. }
  651. d_instantiate(dentry, inode);
  652. }
  653. /* Now set the ACL based on the default value */
  654. v9fs_set_create_acl(dentry, dacl, pacl);
  655. error:
  656. if (fid)
  657. p9_client_clunk(fid);
  658. return err;
  659. }
  660. /**
  661. * v9fs_vfs_follow_link_dotl - follow a symlink path
  662. * @dentry: dentry for symlink
  663. * @nd: nameidata
  664. *
  665. */
  666. static void *
  667. v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
  668. {
  669. int retval;
  670. struct p9_fid *fid;
  671. char *link = __getname();
  672. char *target;
  673. P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name);
  674. if (!link) {
  675. link = ERR_PTR(-ENOMEM);
  676. goto ndset;
  677. }
  678. fid = v9fs_fid_lookup(dentry);
  679. if (IS_ERR(fid)) {
  680. __putname(link);
  681. link = ERR_PTR(PTR_ERR(fid));
  682. goto ndset;
  683. }
  684. retval = p9_client_readlink(fid, &target);
  685. if (!retval) {
  686. strcpy(link, target);
  687. kfree(target);
  688. goto ndset;
  689. }
  690. __putname(link);
  691. link = ERR_PTR(retval);
  692. ndset:
  693. nd_set_link(nd, link);
  694. return NULL;
  695. }
  696. const struct inode_operations v9fs_dir_inode_operations_dotl = {
  697. .create = v9fs_vfs_create_dotl,
  698. .lookup = v9fs_vfs_lookup,
  699. .link = v9fs_vfs_link_dotl,
  700. .symlink = v9fs_vfs_symlink_dotl,
  701. .unlink = v9fs_vfs_unlink,
  702. .mkdir = v9fs_vfs_mkdir_dotl,
  703. .rmdir = v9fs_vfs_rmdir,
  704. .mknod = v9fs_vfs_mknod_dotl,
  705. .rename = v9fs_vfs_rename,
  706. .getattr = v9fs_vfs_getattr_dotl,
  707. .setattr = v9fs_vfs_setattr_dotl,
  708. .setxattr = generic_setxattr,
  709. .getxattr = generic_getxattr,
  710. .removexattr = generic_removexattr,
  711. .listxattr = v9fs_listxattr,
  712. .check_acl = v9fs_check_acl,
  713. };
  714. const struct inode_operations v9fs_file_inode_operations_dotl = {
  715. .getattr = v9fs_vfs_getattr_dotl,
  716. .setattr = v9fs_vfs_setattr_dotl,
  717. .setxattr = generic_setxattr,
  718. .getxattr = generic_getxattr,
  719. .removexattr = generic_removexattr,
  720. .listxattr = v9fs_listxattr,
  721. .check_acl = v9fs_check_acl,
  722. };
  723. const struct inode_operations v9fs_symlink_inode_operations_dotl = {
  724. .readlink = generic_readlink,
  725. .follow_link = v9fs_vfs_follow_link_dotl,
  726. .put_link = v9fs_vfs_put_link,
  727. .getattr = v9fs_vfs_getattr_dotl,
  728. .setattr = v9fs_vfs_setattr_dotl,
  729. .setxattr = generic_setxattr,
  730. .getxattr = generic_getxattr,
  731. .removexattr = generic_removexattr,
  732. .listxattr = v9fs_listxattr,
  733. };