vfs_inode_dotl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. return 0;
  206. error:
  207. if (ofid)
  208. p9_client_clunk(ofid);
  209. if (fid)
  210. p9_client_clunk(fid);
  211. return err;
  212. }
  213. /**
  214. * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
  215. * @dir: inode that is being unlinked
  216. * @dentry: dentry that is being unlinked
  217. * @mode: mode for new directory
  218. *
  219. */
  220. static int v9fs_vfs_mkdir_dotl(struct inode *dir,
  221. struct dentry *dentry, int omode)
  222. {
  223. int err;
  224. struct v9fs_session_info *v9ses;
  225. struct p9_fid *fid = NULL, *dfid = NULL;
  226. gid_t gid;
  227. char *name;
  228. mode_t mode;
  229. struct inode *inode;
  230. struct p9_qid qid;
  231. struct dentry *dir_dentry;
  232. struct posix_acl *dacl = NULL, *pacl = NULL;
  233. P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
  234. err = 0;
  235. v9ses = v9fs_inode2v9ses(dir);
  236. omode |= S_IFDIR;
  237. if (dir->i_mode & S_ISGID)
  238. omode |= S_ISGID;
  239. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  240. dfid = v9fs_fid_lookup(dir_dentry);
  241. if (IS_ERR(dfid)) {
  242. err = PTR_ERR(dfid);
  243. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  244. dfid = NULL;
  245. goto error;
  246. }
  247. gid = v9fs_get_fsgid_for_create(dir);
  248. mode = omode;
  249. /* Update mode based on ACL value */
  250. err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
  251. if (err) {
  252. P9_DPRINTK(P9_DEBUG_VFS,
  253. "Failed to get acl values in mkdir %d\n", err);
  254. goto error;
  255. }
  256. name = (char *) dentry->d_name.name;
  257. err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
  258. if (err < 0)
  259. goto error;
  260. /* instantiate inode and assign the unopened fid to the dentry */
  261. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  262. fid = p9_client_walk(dfid, 1, &name, 1);
  263. if (IS_ERR(fid)) {
  264. err = PTR_ERR(fid);
  265. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  266. err);
  267. fid = NULL;
  268. goto error;
  269. }
  270. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  271. if (IS_ERR(inode)) {
  272. err = PTR_ERR(inode);
  273. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  274. err);
  275. goto error;
  276. }
  277. d_instantiate(dentry, inode);
  278. err = v9fs_fid_add(dentry, fid);
  279. if (err < 0)
  280. goto error;
  281. fid = NULL;
  282. } else {
  283. /*
  284. * Not in cached mode. No need to populate
  285. * inode with stat. We need to get an inode
  286. * so that we can set the acl with dentry
  287. */
  288. inode = v9fs_get_inode(dir->i_sb, mode);
  289. if (IS_ERR(inode)) {
  290. err = PTR_ERR(inode);
  291. goto error;
  292. }
  293. d_instantiate(dentry, inode);
  294. }
  295. /* Now set the ACL based on the default value */
  296. v9fs_set_create_acl(dentry, dacl, pacl);
  297. error:
  298. if (fid)
  299. p9_client_clunk(fid);
  300. return err;
  301. }
  302. static int
  303. v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
  304. struct kstat *stat)
  305. {
  306. int err;
  307. struct v9fs_session_info *v9ses;
  308. struct p9_fid *fid;
  309. struct p9_stat_dotl *st;
  310. P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
  311. err = -EPERM;
  312. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  313. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
  314. return simple_getattr(mnt, dentry, stat);
  315. fid = v9fs_fid_lookup(dentry);
  316. if (IS_ERR(fid))
  317. return PTR_ERR(fid);
  318. /* Ask for all the fields in stat structure. Server will return
  319. * whatever it supports
  320. */
  321. st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
  322. if (IS_ERR(st))
  323. return PTR_ERR(st);
  324. v9fs_stat2inode_dotl(st, dentry->d_inode);
  325. generic_fillattr(dentry->d_inode, stat);
  326. /* Change block size to what the server returned */
  327. stat->blksize = st->st_blksize;
  328. kfree(st);
  329. return 0;
  330. }
  331. /**
  332. * v9fs_vfs_setattr_dotl - set file metadata
  333. * @dentry: file whose metadata to set
  334. * @iattr: metadata assignment structure
  335. *
  336. */
  337. int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
  338. {
  339. int retval;
  340. struct v9fs_session_info *v9ses;
  341. struct p9_fid *fid;
  342. struct p9_iattr_dotl p9attr;
  343. P9_DPRINTK(P9_DEBUG_VFS, "\n");
  344. retval = inode_change_ok(dentry->d_inode, iattr);
  345. if (retval)
  346. return retval;
  347. p9attr.valid = iattr->ia_valid;
  348. p9attr.mode = iattr->ia_mode;
  349. p9attr.uid = iattr->ia_uid;
  350. p9attr.gid = iattr->ia_gid;
  351. p9attr.size = iattr->ia_size;
  352. p9attr.atime_sec = iattr->ia_atime.tv_sec;
  353. p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
  354. p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
  355. p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
  356. retval = -EPERM;
  357. v9ses = v9fs_inode2v9ses(dentry->d_inode);
  358. fid = v9fs_fid_lookup(dentry);
  359. if (IS_ERR(fid))
  360. return PTR_ERR(fid);
  361. retval = p9_client_setattr(fid, &p9attr);
  362. if (retval < 0)
  363. return retval;
  364. if ((iattr->ia_valid & ATTR_SIZE) &&
  365. iattr->ia_size != i_size_read(dentry->d_inode)) {
  366. retval = vmtruncate(dentry->d_inode, iattr->ia_size);
  367. if (retval)
  368. return retval;
  369. }
  370. setattr_copy(dentry->d_inode, iattr);
  371. mark_inode_dirty(dentry->d_inode);
  372. if (iattr->ia_valid & ATTR_MODE) {
  373. /* We also want to update ACL when we update mode bits */
  374. retval = v9fs_acl_chmod(dentry);
  375. if (retval < 0)
  376. return retval;
  377. }
  378. return 0;
  379. }
  380. /**
  381. * v9fs_stat2inode_dotl - populate an inode structure with stat info
  382. * @stat: stat structure
  383. * @inode: inode to populate
  384. * @sb: superblock of filesystem
  385. *
  386. */
  387. void
  388. v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
  389. {
  390. if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
  391. inode->i_atime.tv_sec = stat->st_atime_sec;
  392. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  393. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  394. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  395. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  396. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  397. inode->i_uid = stat->st_uid;
  398. inode->i_gid = stat->st_gid;
  399. inode->i_nlink = stat->st_nlink;
  400. inode->i_mode = stat->st_mode;
  401. inode->i_rdev = new_decode_dev(stat->st_rdev);
  402. if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
  403. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  404. i_size_write(inode, stat->st_size);
  405. inode->i_blocks = stat->st_blocks;
  406. } else {
  407. if (stat->st_result_mask & P9_STATS_ATIME) {
  408. inode->i_atime.tv_sec = stat->st_atime_sec;
  409. inode->i_atime.tv_nsec = stat->st_atime_nsec;
  410. }
  411. if (stat->st_result_mask & P9_STATS_MTIME) {
  412. inode->i_mtime.tv_sec = stat->st_mtime_sec;
  413. inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
  414. }
  415. if (stat->st_result_mask & P9_STATS_CTIME) {
  416. inode->i_ctime.tv_sec = stat->st_ctime_sec;
  417. inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
  418. }
  419. if (stat->st_result_mask & P9_STATS_UID)
  420. inode->i_uid = stat->st_uid;
  421. if (stat->st_result_mask & P9_STATS_GID)
  422. inode->i_gid = stat->st_gid;
  423. if (stat->st_result_mask & P9_STATS_NLINK)
  424. inode->i_nlink = stat->st_nlink;
  425. if (stat->st_result_mask & P9_STATS_MODE) {
  426. inode->i_mode = stat->st_mode;
  427. if ((S_ISBLK(inode->i_mode)) ||
  428. (S_ISCHR(inode->i_mode)))
  429. init_special_inode(inode, inode->i_mode,
  430. inode->i_rdev);
  431. }
  432. if (stat->st_result_mask & P9_STATS_RDEV)
  433. inode->i_rdev = new_decode_dev(stat->st_rdev);
  434. if (stat->st_result_mask & P9_STATS_SIZE)
  435. i_size_write(inode, stat->st_size);
  436. if (stat->st_result_mask & P9_STATS_BLOCKS)
  437. inode->i_blocks = stat->st_blocks;
  438. }
  439. if (stat->st_result_mask & P9_STATS_GEN)
  440. inode->i_generation = stat->st_gen;
  441. /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
  442. * because the inode structure does not have fields for them.
  443. */
  444. }
  445. static int
  446. v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
  447. const char *symname)
  448. {
  449. struct v9fs_session_info *v9ses;
  450. struct p9_fid *dfid;
  451. struct p9_fid *fid = NULL;
  452. struct inode *inode;
  453. struct p9_qid qid;
  454. char *name;
  455. int err;
  456. gid_t gid;
  457. name = (char *) dentry->d_name.name;
  458. P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
  459. dir->i_ino, name, symname);
  460. v9ses = v9fs_inode2v9ses(dir);
  461. dfid = v9fs_fid_lookup(dentry->d_parent);
  462. if (IS_ERR(dfid)) {
  463. err = PTR_ERR(dfid);
  464. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  465. return err;
  466. }
  467. gid = v9fs_get_fsgid_for_create(dir);
  468. /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
  469. err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
  470. if (err < 0) {
  471. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
  472. goto error;
  473. }
  474. if (v9ses->cache) {
  475. /* Now walk from the parent so we can get an unopened fid. */
  476. fid = p9_client_walk(dfid, 1, &name, 1);
  477. if (IS_ERR(fid)) {
  478. err = PTR_ERR(fid);
  479. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  480. err);
  481. fid = NULL;
  482. goto error;
  483. }
  484. /* instantiate inode and assign the unopened fid to dentry */
  485. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  486. if (IS_ERR(inode)) {
  487. err = PTR_ERR(inode);
  488. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  489. err);
  490. goto error;
  491. }
  492. d_instantiate(dentry, inode);
  493. err = v9fs_fid_add(dentry, fid);
  494. if (err < 0)
  495. goto error;
  496. fid = NULL;
  497. } else {
  498. /* Not in cached mode. No need to populate inode with stat */
  499. inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
  500. if (IS_ERR(inode)) {
  501. err = PTR_ERR(inode);
  502. goto error;
  503. }
  504. d_instantiate(dentry, inode);
  505. }
  506. error:
  507. if (fid)
  508. p9_client_clunk(fid);
  509. return err;
  510. }
  511. /**
  512. * v9fs_vfs_link_dotl - create a hardlink for dotl
  513. * @old_dentry: dentry for file to link to
  514. * @dir: inode destination for new link
  515. * @dentry: dentry for link
  516. *
  517. */
  518. static int
  519. v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
  520. struct dentry *dentry)
  521. {
  522. int err;
  523. struct p9_fid *dfid, *oldfid;
  524. char *name;
  525. struct v9fs_session_info *v9ses;
  526. struct dentry *dir_dentry;
  527. P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
  528. dir->i_ino, old_dentry->d_name.name,
  529. dentry->d_name.name);
  530. v9ses = v9fs_inode2v9ses(dir);
  531. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  532. dfid = v9fs_fid_lookup(dir_dentry);
  533. if (IS_ERR(dfid))
  534. return PTR_ERR(dfid);
  535. oldfid = v9fs_fid_lookup(old_dentry);
  536. if (IS_ERR(oldfid))
  537. return PTR_ERR(oldfid);
  538. name = (char *) dentry->d_name.name;
  539. err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
  540. if (err < 0) {
  541. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
  542. return err;
  543. }
  544. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  545. /* Get the latest stat info from server. */
  546. struct p9_fid *fid;
  547. struct p9_stat_dotl *st;
  548. fid = v9fs_fid_lookup(old_dentry);
  549. if (IS_ERR(fid))
  550. return PTR_ERR(fid);
  551. st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
  552. if (IS_ERR(st))
  553. return PTR_ERR(st);
  554. v9fs_stat2inode_dotl(st, old_dentry->d_inode);
  555. kfree(st);
  556. } else {
  557. /* Caching disabled. No need to get upto date stat info.
  558. * This dentry will be released immediately. So, just hold the
  559. * inode
  560. */
  561. ihold(old_dentry->d_inode);
  562. }
  563. d_instantiate(dentry, old_dentry->d_inode);
  564. return err;
  565. }
  566. /**
  567. * v9fs_vfs_mknod_dotl - create a special file
  568. * @dir: inode destination for new link
  569. * @dentry: dentry for file
  570. * @mode: mode for creation
  571. * @rdev: device associated with special file
  572. *
  573. */
  574. static int
  575. v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
  576. dev_t rdev)
  577. {
  578. int err;
  579. char *name;
  580. mode_t mode;
  581. struct v9fs_session_info *v9ses;
  582. struct p9_fid *fid = NULL, *dfid = NULL;
  583. struct inode *inode;
  584. gid_t gid;
  585. struct p9_qid qid;
  586. struct dentry *dir_dentry;
  587. struct posix_acl *dacl = NULL, *pacl = NULL;
  588. P9_DPRINTK(P9_DEBUG_VFS,
  589. " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
  590. dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
  591. if (!new_valid_dev(rdev))
  592. return -EINVAL;
  593. v9ses = v9fs_inode2v9ses(dir);
  594. dir_dentry = v9fs_dentry_from_dir_inode(dir);
  595. dfid = v9fs_fid_lookup(dir_dentry);
  596. if (IS_ERR(dfid)) {
  597. err = PTR_ERR(dfid);
  598. P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
  599. dfid = NULL;
  600. goto error;
  601. }
  602. gid = v9fs_get_fsgid_for_create(dir);
  603. mode = omode;
  604. /* Update mode based on ACL value */
  605. err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
  606. if (err) {
  607. P9_DPRINTK(P9_DEBUG_VFS,
  608. "Failed to get acl values in mknod %d\n", err);
  609. goto error;
  610. }
  611. name = (char *) dentry->d_name.name;
  612. err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
  613. if (err < 0)
  614. goto error;
  615. /* instantiate inode and assign the unopened fid to the dentry */
  616. if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
  617. fid = p9_client_walk(dfid, 1, &name, 1);
  618. if (IS_ERR(fid)) {
  619. err = PTR_ERR(fid);
  620. P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
  621. err);
  622. fid = NULL;
  623. goto error;
  624. }
  625. inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
  626. if (IS_ERR(inode)) {
  627. err = PTR_ERR(inode);
  628. P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
  629. err);
  630. goto error;
  631. }
  632. d_instantiate(dentry, inode);
  633. err = v9fs_fid_add(dentry, fid);
  634. if (err < 0)
  635. goto error;
  636. fid = NULL;
  637. } else {
  638. /*
  639. * Not in cached mode. No need to populate inode with stat.
  640. * socket syscall returns a fd, so we need instantiate
  641. */
  642. inode = v9fs_get_inode(dir->i_sb, mode);
  643. if (IS_ERR(inode)) {
  644. err = PTR_ERR(inode);
  645. goto error;
  646. }
  647. d_instantiate(dentry, inode);
  648. }
  649. /* Now set the ACL based on the default value */
  650. v9fs_set_create_acl(dentry, dacl, pacl);
  651. error:
  652. if (fid)
  653. p9_client_clunk(fid);
  654. return err;
  655. }
  656. /**
  657. * v9fs_vfs_follow_link_dotl - follow a symlink path
  658. * @dentry: dentry for symlink
  659. * @nd: nameidata
  660. *
  661. */
  662. static void *
  663. v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
  664. {
  665. int retval;
  666. struct p9_fid *fid;
  667. char *link = __getname();
  668. char *target;
  669. P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name);
  670. if (!link) {
  671. link = ERR_PTR(-ENOMEM);
  672. goto ndset;
  673. }
  674. fid = v9fs_fid_lookup(dentry);
  675. if (IS_ERR(fid)) {
  676. __putname(link);
  677. link = ERR_PTR(PTR_ERR(fid));
  678. goto ndset;
  679. }
  680. retval = p9_client_readlink(fid, &target);
  681. if (!retval) {
  682. strcpy(link, target);
  683. kfree(target);
  684. goto ndset;
  685. }
  686. __putname(link);
  687. link = ERR_PTR(retval);
  688. ndset:
  689. nd_set_link(nd, link);
  690. return NULL;
  691. }
  692. const struct inode_operations v9fs_dir_inode_operations_dotl = {
  693. .create = v9fs_vfs_create_dotl,
  694. .lookup = v9fs_vfs_lookup,
  695. .link = v9fs_vfs_link_dotl,
  696. .symlink = v9fs_vfs_symlink_dotl,
  697. .unlink = v9fs_vfs_unlink,
  698. .mkdir = v9fs_vfs_mkdir_dotl,
  699. .rmdir = v9fs_vfs_rmdir,
  700. .mknod = v9fs_vfs_mknod_dotl,
  701. .rename = v9fs_vfs_rename,
  702. .getattr = v9fs_vfs_getattr_dotl,
  703. .setattr = v9fs_vfs_setattr_dotl,
  704. .setxattr = generic_setxattr,
  705. .getxattr = generic_getxattr,
  706. .removexattr = generic_removexattr,
  707. .listxattr = v9fs_listxattr,
  708. .check_acl = v9fs_check_acl,
  709. };
  710. const struct inode_operations v9fs_file_inode_operations_dotl = {
  711. .getattr = v9fs_vfs_getattr_dotl,
  712. .setattr = v9fs_vfs_setattr_dotl,
  713. .setxattr = generic_setxattr,
  714. .getxattr = generic_getxattr,
  715. .removexattr = generic_removexattr,
  716. .listxattr = v9fs_listxattr,
  717. .check_acl = v9fs_check_acl,
  718. };
  719. const struct inode_operations v9fs_symlink_inode_operations_dotl = {
  720. .readlink = generic_readlink,
  721. .follow_link = v9fs_vfs_follow_link_dotl,
  722. .put_link = v9fs_vfs_put_link,
  723. .getattr = v9fs_vfs_getattr_dotl,
  724. .setattr = v9fs_vfs_setattr_dotl,
  725. .setxattr = generic_setxattr,
  726. .getxattr = generic_getxattr,
  727. .removexattr = generic_removexattr,
  728. .listxattr = v9fs_listxattr,
  729. };