fs/9p: Add v9fs_inode
[pandora-kernel.git] / fs / 9p / vfs_inode_dotl.c
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
26 #include <linux/module.h>
27 #include <linux/errno.h>
28 #include <linux/fs.h>
29 #include <linux/file.h>
30 #include <linux/pagemap.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/inet.h>
34 #include <linux/namei.h>
35 #include <linux/idr.h>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <linux/xattr.h>
39 #include <linux/posix_acl.h>
40 #include <net/9p/9p.h>
41 #include <net/9p/client.h>
42
43 #include "v9fs.h"
44 #include "v9fs_vfs.h"
45 #include "fid.h"
46 #include "cache.h"
47 #include "xattr.h"
48 #include "acl.h"
49
50 static int
51 v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
52                     dev_t rdev);
53
54 /**
55  * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
56  * new file system object. This checks the S_ISGID to determine the owning
57  * group of the new file system object.
58  */
59
60 static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
61 {
62         BUG_ON(dir_inode == NULL);
63
64         if (dir_inode->i_mode & S_ISGID) {
65                 /* set_gid bit is set.*/
66                 return dir_inode->i_gid;
67         }
68         return current_fsgid();
69 }
70
71 /**
72  * v9fs_dentry_from_dir_inode - helper function to get the dentry from
73  * dir inode.
74  *
75  */
76
77 static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
78 {
79         struct dentry *dentry;
80
81         spin_lock(&inode->i_lock);
82         /* Directory should have only one entry. */
83         BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
84         dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
85         spin_unlock(&inode->i_lock);
86         return dentry;
87 }
88
89 static struct inode *v9fs_qid_iget_dotl(struct super_block *sb,
90                                         struct p9_qid *qid,
91                                         struct p9_fid *fid,
92                                         struct p9_stat_dotl *st)
93 {
94         int retval;
95         unsigned long i_ino;
96         struct inode *inode;
97         struct v9fs_session_info *v9ses = sb->s_fs_info;
98
99         i_ino = v9fs_qid2ino(qid);
100         inode = iget_locked(sb, i_ino);
101         if (!inode)
102                 return ERR_PTR(-ENOMEM);
103         if (!(inode->i_state & I_NEW))
104                 return inode;
105         /*
106          * initialize the inode with the stat info
107          * FIXME!! we may need support for stale inodes
108          * later.
109          */
110         retval = v9fs_init_inode(v9ses, inode, st->st_mode);
111         if (retval)
112                 goto error;
113
114         v9fs_stat2inode_dotl(st, inode);
115 #ifdef CONFIG_9P_FSCACHE
116         v9fs_fscache_set_key(inode, &st->qid);
117         v9fs_cache_inode_get_cookie(inode);
118 #endif
119         retval = v9fs_get_acl(inode, fid);
120         if (retval)
121                 goto error;
122
123         unlock_new_inode(inode);
124         return inode;
125 error:
126         unlock_new_inode(inode);
127         iput(inode);
128         return ERR_PTR(retval);
129
130 }
131
132 struct inode *
133 v9fs_inode_from_fid_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
134                          struct super_block *sb)
135 {
136         struct p9_stat_dotl *st;
137         struct inode *inode = NULL;
138
139         st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
140         if (IS_ERR(st))
141                 return ERR_CAST(st);
142
143         inode = v9fs_qid_iget_dotl(sb, &st->qid, fid, st);
144         kfree(st);
145         return inode;
146 }
147
148 /**
149  * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
150  * @dir: directory inode that is being created
151  * @dentry:  dentry that is being deleted
152  * @mode: create permissions
153  * @nd: path information
154  *
155  */
156
157 static int
158 v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode,
159                 struct nameidata *nd)
160 {
161         int err = 0;
162         char *name = NULL;
163         gid_t gid;
164         int flags;
165         mode_t mode;
166         struct v9fs_session_info *v9ses;
167         struct p9_fid *fid = NULL;
168         struct p9_fid *dfid, *ofid, *inode_fid;
169         struct file *filp;
170         struct p9_qid qid;
171         struct inode *inode;
172         struct posix_acl *pacl = NULL, *dacl = NULL;
173
174         v9ses = v9fs_inode2v9ses(dir);
175         if (nd && nd->flags & LOOKUP_OPEN)
176                 flags = nd->intent.open.flags - 1;
177         else {
178                 /*
179                  * create call without LOOKUP_OPEN is due
180                  * to mknod of regular files. So use mknod
181                  * operation.
182                  */
183                 return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0);
184         }
185
186         name = (char *) dentry->d_name.name;
187         P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
188                         "mode:0x%x\n", name, flags, omode);
189
190         dfid = v9fs_fid_lookup(dentry->d_parent);
191         if (IS_ERR(dfid)) {
192                 err = PTR_ERR(dfid);
193                 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
194                 return err;
195         }
196
197         /* clone a fid to use for creation */
198         ofid = p9_client_walk(dfid, 0, NULL, 1);
199         if (IS_ERR(ofid)) {
200                 err = PTR_ERR(ofid);
201                 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
202                 return err;
203         }
204
205         gid = v9fs_get_fsgid_for_create(dir);
206
207         mode = omode;
208         /* Update mode based on ACL value */
209         err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
210         if (err) {
211                 P9_DPRINTK(P9_DEBUG_VFS,
212                            "Failed to get acl values in creat %d\n", err);
213                 goto error;
214         }
215         err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
216         if (err < 0) {
217                 P9_DPRINTK(P9_DEBUG_VFS,
218                                 "p9_client_open_dotl failed in creat %d\n",
219                                 err);
220                 goto error;
221         }
222
223         /* instantiate inode and assign the unopened fid to the dentry */
224         fid = p9_client_walk(dfid, 1, &name, 1);
225         if (IS_ERR(fid)) {
226                 err = PTR_ERR(fid);
227                 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
228                 fid = NULL;
229                 goto error;
230         }
231         inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
232         if (IS_ERR(inode)) {
233                 err = PTR_ERR(inode);
234                 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
235                 goto error;
236         }
237         d_instantiate(dentry, inode);
238         err = v9fs_fid_add(dentry, fid);
239         if (err < 0)
240                 goto error;
241
242         /* Now set the ACL based on the default value */
243         v9fs_set_create_acl(dentry, dacl, pacl);
244         if (v9ses->cache && !inode->i_private) {
245                 /*
246                  * clone a fid and add it to inode->i_private
247                  * we do it during open time instead of
248                  * page dirty time via write_begin/page_mkwrite
249                  * because we want write after unlink usecase
250                  * to work.
251                  */
252                 inode_fid = v9fs_writeback_fid(dentry);
253                 if (IS_ERR(inode_fid)) {
254                         err = PTR_ERR(inode_fid);
255                         goto error;
256                 }
257                 inode->i_private = (void *) inode_fid;
258         }
259         /* Since we are opening a file, assign the open fid to the file */
260         filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
261         if (IS_ERR(filp)) {
262                 p9_client_clunk(ofid);
263                 return PTR_ERR(filp);
264         }
265         filp->private_data = ofid;
266 #ifdef CONFIG_9P_FSCACHE
267         if (v9ses->cache)
268                 v9fs_cache_inode_set_cookie(inode, filp);
269 #endif
270         return 0;
271
272 error:
273         if (ofid)
274                 p9_client_clunk(ofid);
275         if (fid)
276                 p9_client_clunk(fid);
277         return err;
278 }
279
280 /**
281  * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
282  * @dir:  inode that is being unlinked
283  * @dentry: dentry that is being unlinked
284  * @mode: mode for new directory
285  *
286  */
287
288 static int v9fs_vfs_mkdir_dotl(struct inode *dir,
289                                struct dentry *dentry, int omode)
290 {
291         int err;
292         struct v9fs_session_info *v9ses;
293         struct p9_fid *fid = NULL, *dfid = NULL;
294         gid_t gid;
295         char *name;
296         mode_t mode;
297         struct inode *inode;
298         struct p9_qid qid;
299         struct dentry *dir_dentry;
300         struct posix_acl *dacl = NULL, *pacl = NULL;
301
302         P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
303         err = 0;
304         v9ses = v9fs_inode2v9ses(dir);
305
306         omode |= S_IFDIR;
307         if (dir->i_mode & S_ISGID)
308                 omode |= S_ISGID;
309
310         dir_dentry = v9fs_dentry_from_dir_inode(dir);
311         dfid = v9fs_fid_lookup(dir_dentry);
312         if (IS_ERR(dfid)) {
313                 err = PTR_ERR(dfid);
314                 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
315                 dfid = NULL;
316                 goto error;
317         }
318
319         gid = v9fs_get_fsgid_for_create(dir);
320         mode = omode;
321         /* Update mode based on ACL value */
322         err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
323         if (err) {
324                 P9_DPRINTK(P9_DEBUG_VFS,
325                            "Failed to get acl values in mkdir %d\n", err);
326                 goto error;
327         }
328         name = (char *) dentry->d_name.name;
329         err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
330         if (err < 0)
331                 goto error;
332
333         /* instantiate inode and assign the unopened fid to the dentry */
334         if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
335                 fid = p9_client_walk(dfid, 1, &name, 1);
336                 if (IS_ERR(fid)) {
337                         err = PTR_ERR(fid);
338                         P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
339                                 err);
340                         fid = NULL;
341                         goto error;
342                 }
343
344                 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
345                 if (IS_ERR(inode)) {
346                         err = PTR_ERR(inode);
347                         P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
348                                 err);
349                         goto error;
350                 }
351                 d_instantiate(dentry, inode);
352                 err = v9fs_fid_add(dentry, fid);
353                 if (err < 0)
354                         goto error;
355                 fid = NULL;
356         } else {
357                 /*
358                  * Not in cached mode. No need to populate
359                  * inode with stat. We need to get an inode
360                  * so that we can set the acl with dentry
361                  */
362                 inode = v9fs_get_inode(dir->i_sb, mode);
363                 if (IS_ERR(inode)) {
364                         err = PTR_ERR(inode);
365                         goto error;
366                 }
367                 d_instantiate(dentry, inode);
368         }
369         /* Now set the ACL based on the default value */
370         v9fs_set_create_acl(dentry, dacl, pacl);
371
372 error:
373         if (fid)
374                 p9_client_clunk(fid);
375         return err;
376 }
377
378 static int
379 v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
380                  struct kstat *stat)
381 {
382         int err;
383         struct v9fs_session_info *v9ses;
384         struct p9_fid *fid;
385         struct p9_stat_dotl *st;
386
387         P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
388         err = -EPERM;
389         v9ses = v9fs_inode2v9ses(dentry->d_inode);
390         if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
391                 generic_fillattr(dentry->d_inode, stat);
392                 return 0;
393         }
394         fid = v9fs_fid_lookup(dentry);
395         if (IS_ERR(fid))
396                 return PTR_ERR(fid);
397
398         /* Ask for all the fields in stat structure. Server will return
399          * whatever it supports
400          */
401
402         st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
403         if (IS_ERR(st))
404                 return PTR_ERR(st);
405
406         v9fs_stat2inode_dotl(st, dentry->d_inode);
407         generic_fillattr(dentry->d_inode, stat);
408         /* Change block size to what the server returned */
409         stat->blksize = st->st_blksize;
410
411         kfree(st);
412         return 0;
413 }
414
415 /**
416  * v9fs_vfs_setattr_dotl - set file metadata
417  * @dentry: file whose metadata to set
418  * @iattr: metadata assignment structure
419  *
420  */
421
422 int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
423 {
424         int retval;
425         struct v9fs_session_info *v9ses;
426         struct p9_fid *fid;
427         struct p9_iattr_dotl p9attr;
428
429         P9_DPRINTK(P9_DEBUG_VFS, "\n");
430
431         retval = inode_change_ok(dentry->d_inode, iattr);
432         if (retval)
433                 return retval;
434
435         p9attr.valid = iattr->ia_valid;
436         p9attr.mode = iattr->ia_mode;
437         p9attr.uid = iattr->ia_uid;
438         p9attr.gid = iattr->ia_gid;
439         p9attr.size = iattr->ia_size;
440         p9attr.atime_sec = iattr->ia_atime.tv_sec;
441         p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
442         p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
443         p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
444
445         retval = -EPERM;
446         v9ses = v9fs_inode2v9ses(dentry->d_inode);
447         fid = v9fs_fid_lookup(dentry);
448         if (IS_ERR(fid))
449                 return PTR_ERR(fid);
450
451         retval = p9_client_setattr(fid, &p9attr);
452         if (retval < 0)
453                 return retval;
454
455         if ((iattr->ia_valid & ATTR_SIZE) &&
456             iattr->ia_size != i_size_read(dentry->d_inode)) {
457                 retval = vmtruncate(dentry->d_inode, iattr->ia_size);
458                 if (retval)
459                         return retval;
460         }
461
462         setattr_copy(dentry->d_inode, iattr);
463         mark_inode_dirty(dentry->d_inode);
464         if (iattr->ia_valid & ATTR_MODE) {
465                 /* We also want to update ACL when we update mode bits */
466                 retval = v9fs_acl_chmod(dentry);
467                 if (retval < 0)
468                         return retval;
469         }
470         return 0;
471 }
472
473 /**
474  * v9fs_stat2inode_dotl - populate an inode structure with stat info
475  * @stat: stat structure
476  * @inode: inode to populate
477  * @sb: superblock of filesystem
478  *
479  */
480
481 void
482 v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
483 {
484
485         if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
486                 inode->i_atime.tv_sec = stat->st_atime_sec;
487                 inode->i_atime.tv_nsec = stat->st_atime_nsec;
488                 inode->i_mtime.tv_sec = stat->st_mtime_sec;
489                 inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
490                 inode->i_ctime.tv_sec = stat->st_ctime_sec;
491                 inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
492                 inode->i_uid = stat->st_uid;
493                 inode->i_gid = stat->st_gid;
494                 inode->i_nlink = stat->st_nlink;
495                 inode->i_mode = stat->st_mode;
496                 inode->i_rdev = new_decode_dev(stat->st_rdev);
497
498                 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
499                         init_special_inode(inode, inode->i_mode, inode->i_rdev);
500
501                 i_size_write(inode, stat->st_size);
502                 inode->i_blocks = stat->st_blocks;
503         } else {
504                 if (stat->st_result_mask & P9_STATS_ATIME) {
505                         inode->i_atime.tv_sec = stat->st_atime_sec;
506                         inode->i_atime.tv_nsec = stat->st_atime_nsec;
507                 }
508                 if (stat->st_result_mask & P9_STATS_MTIME) {
509                         inode->i_mtime.tv_sec = stat->st_mtime_sec;
510                         inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
511                 }
512                 if (stat->st_result_mask & P9_STATS_CTIME) {
513                         inode->i_ctime.tv_sec = stat->st_ctime_sec;
514                         inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
515                 }
516                 if (stat->st_result_mask & P9_STATS_UID)
517                         inode->i_uid = stat->st_uid;
518                 if (stat->st_result_mask & P9_STATS_GID)
519                         inode->i_gid = stat->st_gid;
520                 if (stat->st_result_mask & P9_STATS_NLINK)
521                         inode->i_nlink = stat->st_nlink;
522                 if (stat->st_result_mask & P9_STATS_MODE) {
523                         inode->i_mode = stat->st_mode;
524                         if ((S_ISBLK(inode->i_mode)) ||
525                                                 (S_ISCHR(inode->i_mode)))
526                                 init_special_inode(inode, inode->i_mode,
527                                                                 inode->i_rdev);
528                 }
529                 if (stat->st_result_mask & P9_STATS_RDEV)
530                         inode->i_rdev = new_decode_dev(stat->st_rdev);
531                 if (stat->st_result_mask & P9_STATS_SIZE)
532                         i_size_write(inode, stat->st_size);
533                 if (stat->st_result_mask & P9_STATS_BLOCKS)
534                         inode->i_blocks = stat->st_blocks;
535         }
536         if (stat->st_result_mask & P9_STATS_GEN)
537                         inode->i_generation = stat->st_gen;
538
539         /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
540          * because the inode structure does not have fields for them.
541          */
542 }
543
544 static int
545 v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
546                 const char *symname)
547 {
548         struct v9fs_session_info *v9ses;
549         struct p9_fid *dfid;
550         struct p9_fid *fid = NULL;
551         struct inode *inode;
552         struct p9_qid qid;
553         char *name;
554         int err;
555         gid_t gid;
556
557         name = (char *) dentry->d_name.name;
558         P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
559                         dir->i_ino, name, symname);
560         v9ses = v9fs_inode2v9ses(dir);
561
562         dfid = v9fs_fid_lookup(dentry->d_parent);
563         if (IS_ERR(dfid)) {
564                 err = PTR_ERR(dfid);
565                 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
566                 return err;
567         }
568
569         gid = v9fs_get_fsgid_for_create(dir);
570
571         /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
572         err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
573
574         if (err < 0) {
575                 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
576                 goto error;
577         }
578
579         if (v9ses->cache) {
580                 /* Now walk from the parent so we can get an unopened fid. */
581                 fid = p9_client_walk(dfid, 1, &name, 1);
582                 if (IS_ERR(fid)) {
583                         err = PTR_ERR(fid);
584                         P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
585                                         err);
586                         fid = NULL;
587                         goto error;
588                 }
589
590                 /* instantiate inode and assign the unopened fid to dentry */
591                 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
592                 if (IS_ERR(inode)) {
593                         err = PTR_ERR(inode);
594                         P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
595                                         err);
596                         goto error;
597                 }
598                 d_instantiate(dentry, inode);
599                 err = v9fs_fid_add(dentry, fid);
600                 if (err < 0)
601                         goto error;
602                 fid = NULL;
603         } else {
604                 /* Not in cached mode. No need to populate inode with stat */
605                 inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
606                 if (IS_ERR(inode)) {
607                         err = PTR_ERR(inode);
608                         goto error;
609                 }
610                 d_instantiate(dentry, inode);
611         }
612
613 error:
614         if (fid)
615                 p9_client_clunk(fid);
616
617         return err;
618 }
619
620 /**
621  * v9fs_vfs_link_dotl - create a hardlink for dotl
622  * @old_dentry: dentry for file to link to
623  * @dir: inode destination for new link
624  * @dentry: dentry for link
625  *
626  */
627
628 static int
629 v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
630                 struct dentry *dentry)
631 {
632         int err;
633         struct p9_fid *dfid, *oldfid;
634         char *name;
635         struct v9fs_session_info *v9ses;
636         struct dentry *dir_dentry;
637
638         P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
639                         dir->i_ino, old_dentry->d_name.name,
640                         dentry->d_name.name);
641
642         v9ses = v9fs_inode2v9ses(dir);
643         dir_dentry = v9fs_dentry_from_dir_inode(dir);
644         dfid = v9fs_fid_lookup(dir_dentry);
645         if (IS_ERR(dfid))
646                 return PTR_ERR(dfid);
647
648         oldfid = v9fs_fid_lookup(old_dentry);
649         if (IS_ERR(oldfid))
650                 return PTR_ERR(oldfid);
651
652         name = (char *) dentry->d_name.name;
653
654         err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
655
656         if (err < 0) {
657                 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
658                 return err;
659         }
660
661         if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
662                 /* Get the latest stat info from server. */
663                 struct p9_fid *fid;
664                 struct p9_stat_dotl *st;
665
666                 fid = v9fs_fid_lookup(old_dentry);
667                 if (IS_ERR(fid))
668                         return PTR_ERR(fid);
669
670                 st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
671                 if (IS_ERR(st))
672                         return PTR_ERR(st);
673
674                 v9fs_stat2inode_dotl(st, old_dentry->d_inode);
675
676                 kfree(st);
677         }
678         ihold(old_dentry->d_inode);
679         d_instantiate(dentry, old_dentry->d_inode);
680
681         return err;
682 }
683
684 /**
685  * v9fs_vfs_mknod_dotl - create a special file
686  * @dir: inode destination for new link
687  * @dentry: dentry for file
688  * @mode: mode for creation
689  * @rdev: device associated with special file
690  *
691  */
692 static int
693 v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode,
694                 dev_t rdev)
695 {
696         int err;
697         char *name;
698         mode_t mode;
699         struct v9fs_session_info *v9ses;
700         struct p9_fid *fid = NULL, *dfid = NULL;
701         struct inode *inode;
702         gid_t gid;
703         struct p9_qid qid;
704         struct dentry *dir_dentry;
705         struct posix_acl *dacl = NULL, *pacl = NULL;
706
707         P9_DPRINTK(P9_DEBUG_VFS,
708                 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
709                 dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev));
710
711         if (!new_valid_dev(rdev))
712                 return -EINVAL;
713
714         v9ses = v9fs_inode2v9ses(dir);
715         dir_dentry = v9fs_dentry_from_dir_inode(dir);
716         dfid = v9fs_fid_lookup(dir_dentry);
717         if (IS_ERR(dfid)) {
718                 err = PTR_ERR(dfid);
719                 P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
720                 dfid = NULL;
721                 goto error;
722         }
723
724         gid = v9fs_get_fsgid_for_create(dir);
725         mode = omode;
726         /* Update mode based on ACL value */
727         err = v9fs_acl_mode(dir, &mode, &dacl, &pacl);
728         if (err) {
729                 P9_DPRINTK(P9_DEBUG_VFS,
730                            "Failed to get acl values in mknod %d\n", err);
731                 goto error;
732         }
733         name = (char *) dentry->d_name.name;
734
735         err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
736         if (err < 0)
737                 goto error;
738
739         /* instantiate inode and assign the unopened fid to the dentry */
740         if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
741                 fid = p9_client_walk(dfid, 1, &name, 1);
742                 if (IS_ERR(fid)) {
743                         err = PTR_ERR(fid);
744                         P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
745                                 err);
746                         fid = NULL;
747                         goto error;
748                 }
749
750                 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb);
751                 if (IS_ERR(inode)) {
752                         err = PTR_ERR(inode);
753                         P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
754                                 err);
755                         goto error;
756                 }
757                 d_instantiate(dentry, inode);
758                 err = v9fs_fid_add(dentry, fid);
759                 if (err < 0)
760                         goto error;
761                 fid = NULL;
762         } else {
763                 /*
764                  * Not in cached mode. No need to populate inode with stat.
765                  * socket syscall returns a fd, so we need instantiate
766                  */
767                 inode = v9fs_get_inode(dir->i_sb, mode);
768                 if (IS_ERR(inode)) {
769                         err = PTR_ERR(inode);
770                         goto error;
771                 }
772                 d_instantiate(dentry, inode);
773         }
774         /* Now set the ACL based on the default value */
775         v9fs_set_create_acl(dentry, dacl, pacl);
776 error:
777         if (fid)
778                 p9_client_clunk(fid);
779         return err;
780 }
781
782 /**
783  * v9fs_vfs_follow_link_dotl - follow a symlink path
784  * @dentry: dentry for symlink
785  * @nd: nameidata
786  *
787  */
788
789 static void *
790 v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd)
791 {
792         int retval;
793         struct p9_fid *fid;
794         char *link = __getname();
795         char *target;
796
797         P9_DPRINTK(P9_DEBUG_VFS, "%s\n", dentry->d_name.name);
798
799         if (!link) {
800                 link = ERR_PTR(-ENOMEM);
801                 goto ndset;
802         }
803         fid = v9fs_fid_lookup(dentry);
804         if (IS_ERR(fid)) {
805                 __putname(link);
806                 link = ERR_PTR(PTR_ERR(fid));
807                 goto ndset;
808         }
809         retval = p9_client_readlink(fid, &target);
810         if (!retval) {
811                 strcpy(link, target);
812                 kfree(target);
813                 goto ndset;
814         }
815         __putname(link);
816         link = ERR_PTR(retval);
817 ndset:
818         nd_set_link(nd, link);
819         return NULL;
820 }
821
822 const struct inode_operations v9fs_dir_inode_operations_dotl = {
823         .create = v9fs_vfs_create_dotl,
824         .lookup = v9fs_vfs_lookup,
825         .link = v9fs_vfs_link_dotl,
826         .symlink = v9fs_vfs_symlink_dotl,
827         .unlink = v9fs_vfs_unlink,
828         .mkdir = v9fs_vfs_mkdir_dotl,
829         .rmdir = v9fs_vfs_rmdir,
830         .mknod = v9fs_vfs_mknod_dotl,
831         .rename = v9fs_vfs_rename,
832         .getattr = v9fs_vfs_getattr_dotl,
833         .setattr = v9fs_vfs_setattr_dotl,
834         .setxattr = generic_setxattr,
835         .getxattr = generic_getxattr,
836         .removexattr = generic_removexattr,
837         .listxattr = v9fs_listxattr,
838         .check_acl = v9fs_check_acl,
839 };
840
841 const struct inode_operations v9fs_file_inode_operations_dotl = {
842         .getattr = v9fs_vfs_getattr_dotl,
843         .setattr = v9fs_vfs_setattr_dotl,
844         .setxattr = generic_setxattr,
845         .getxattr = generic_getxattr,
846         .removexattr = generic_removexattr,
847         .listxattr = v9fs_listxattr,
848         .check_acl = v9fs_check_acl,
849 };
850
851 const struct inode_operations v9fs_symlink_inode_operations_dotl = {
852         .readlink = generic_readlink,
853         .follow_link = v9fs_vfs_follow_link_dotl,
854         .put_link = v9fs_vfs_put_link,
855         .getattr = v9fs_vfs_getattr_dotl,
856         .setattr = v9fs_vfs_setattr_dotl,
857         .setxattr = generic_setxattr,
858         .getxattr = generic_getxattr,
859         .removexattr = generic_removexattr,
860         .listxattr = v9fs_listxattr,
861 };