Whamcloud - gitweb
Set the ino earlier - it appears that the second RPC reply does not set it.
[fs/lustre-release.git] / lustre / llite / symlink.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #define DEBUG_SUBSYSTEM S_LLITE
23
24 #include <linux/lustre_lite.h>
25
26 static int ll_readlink_internal(struct inode *inode,
27                                 struct ptlrpc_request **request, char **symname)
28 {
29         struct ll_inode_info *lli = ll_i2info(inode);
30         struct ll_sb_info *sbi = ll_i2sbi(inode);
31         int rc, len = inode->i_size + 1;
32         ENTRY;
33
34         *request = NULL;
35
36         if (lli->lli_symlink_name) {
37                 *symname = lli->lli_symlink_name;
38                 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
39                 RETURN(0);
40         }
41
42         rc = mdc_getattr(&sbi->ll_mdc_conn, inode->i_ino, S_IFLNK,
43                          OBD_MD_LINKNAME, len, request);
44         if (rc) {
45                 CERROR("inode "LPD64": rc = %d\n", inode->i_ino, rc);
46                 RETURN(rc);
47         }
48
49         *symname = lustre_msg_buf((*request)->rq_repmsg, 1);
50
51         OBD_ALLOC(lli->lli_symlink_name, len);
52         /* do not return an error if we cannot cache the symlink locally */
53         if (lli->lli_symlink_name)
54                 memcpy(lli->lli_symlink_name, *symname, len);
55
56         RETURN(0);
57 }
58
59 static int ll_readlink(struct dentry *dentry, char *buffer, int buflen)
60 {
61         struct inode *inode = dentry->d_inode;
62         struct ll_inode_info *lli = ll_i2info(inode);
63         struct ptlrpc_request *request;
64         char *symname;
65         int rc;
66         ENTRY;
67
68         /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
69         down(&lli->lli_open_sem);
70         rc = ll_readlink_internal(inode, &request, &symname);
71         if (rc)
72                 GOTO(out, rc);
73
74         rc = vfs_readlink(dentry, buffer, buflen, symname);
75  out:
76         up(&lli->lli_open_sem);
77         ptlrpc_free_req(request);
78
79         RETURN(rc);
80 }
81
82 static int ll_follow_link(struct dentry *dentry, struct nameidata *nd)
83 {
84         struct inode *inode = dentry->d_inode;
85         struct ll_inode_info *lli = ll_i2info(inode);
86         struct ptlrpc_request *request;
87         char *symname;
88         int rc;
89         ENTRY;
90
91         down(&lli->lli_open_sem);
92         rc = ll_readlink_internal(inode, &request, &symname);
93         if (rc)
94                 GOTO(out, rc);
95
96         rc = vfs_follow_link(nd, symname);
97  out:
98         up(&lli->lli_open_sem);
99         ptlrpc_free_req(request);
100
101         RETURN(rc);
102 }
103
104 extern int ll_setattr(struct dentry *de, struct iattr *attr);
105 struct inode_operations ll_fast_symlink_inode_operations = {
106         readlink:       ll_readlink,
107         setattr:        ll_setattr,
108         follow_link:    ll_follow_link
109 };