1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#include <linux/fs.h>
34#include <linux/mm.h>
35#include <linux/stat.h>
36#define DEBUG_SUBSYSTEM S_LLITE
37
38#include "llite_internal.h"
39
40static int ll_readlink_internal(struct inode *inode,
41 struct ptlrpc_request **request, char **symname)
42{
43 struct ll_inode_info *lli = ll_i2info(inode);
44 struct ll_sb_info *sbi = ll_i2sbi(inode);
45 int rc, symlen = i_size_read(inode) + 1;
46 struct mdt_body *body;
47 struct md_op_data *op_data;
48
49 *request = NULL;
50
51 if (lli->lli_symlink_name) {
52 int print_limit = min_t(int, PAGE_SIZE - 128, symlen);
53
54 *symname = lli->lli_symlink_name;
55
56
57
58
59 CDEBUG(D_INODE, "using cached symlink %s%.*s, len = %d\n",
60 print_limit < symlen ? "..." : "", print_limit,
61 (*symname) + symlen - print_limit, symlen);
62 return 0;
63 }
64
65 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, symlen,
66 LUSTRE_OPC_ANY, NULL);
67 if (IS_ERR(op_data))
68 return PTR_ERR(op_data);
69
70 op_data->op_valid = OBD_MD_LINKNAME;
71 rc = md_getattr(sbi->ll_md_exp, op_data, request);
72 ll_finish_md_op_data(op_data);
73 if (rc) {
74 if (rc != -ENOENT)
75 CERROR("%s: inode "DFID": rc = %d\n",
76 ll_get_fsname(inode->i_sb, NULL, 0),
77 PFID(ll_inode2fid(inode)), rc);
78 goto failed;
79 }
80
81 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
82 if ((body->mbo_valid & OBD_MD_LINKNAME) == 0) {
83 CERROR("OBD_MD_LINKNAME not set on reply\n");
84 rc = -EPROTO;
85 goto failed;
86 }
87
88 LASSERT(symlen != 0);
89 if (body->mbo_eadatasize != symlen) {
90 CERROR("%s: inode "DFID": symlink length %d not expected %d\n",
91 ll_get_fsname(inode->i_sb, NULL, 0),
92 PFID(ll_inode2fid(inode)), body->mbo_eadatasize - 1,
93 symlen - 1);
94 rc = -EPROTO;
95 goto failed;
96 }
97
98 *symname = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_MD);
99 if (!*symname ||
100 strnlen(*symname, symlen) != symlen - 1) {
101
102 CERROR("inode %lu: symlink not NULL terminated string of length %d\n",
103 inode->i_ino, symlen - 1);
104 rc = -EPROTO;
105 goto failed;
106 }
107
108 lli->lli_symlink_name = kzalloc(symlen, GFP_NOFS);
109
110 if (lli->lli_symlink_name) {
111 memcpy(lli->lli_symlink_name, *symname, symlen);
112 *symname = lli->lli_symlink_name;
113 }
114 return 0;
115
116failed:
117 return rc;
118}
119
120static void ll_put_link(void *p)
121{
122 ptlrpc_req_finished(p);
123}
124
125static const char *ll_get_link(struct dentry *dentry,
126 struct inode *inode,
127 struct delayed_call *done)
128{
129 struct ptlrpc_request *request = NULL;
130 int rc;
131 char *symname = NULL;
132 if (!dentry)
133 return ERR_PTR(-ECHILD);
134
135 CDEBUG(D_VFSTRACE, "VFS Op\n");
136 ll_inode_size_lock(inode);
137 rc = ll_readlink_internal(inode, &request, &symname);
138 ll_inode_size_unlock(inode);
139 if (rc) {
140 ptlrpc_req_finished(request);
141 return ERR_PTR(rc);
142 }
143
144
145
146
147 set_delayed_call(done, ll_put_link, request);
148 return symname;
149}
150
151const struct inode_operations ll_fast_symlink_inode_operations = {
152 .readlink = generic_readlink,
153 .setattr = ll_setattr,
154 .get_link = ll_get_link,
155 .getattr = ll_getattr,
156 .permission = ll_inode_permission,
157 .listxattr = ll_listxattr,
158};
159