4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2012, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <linux/stat.h>
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include "llite_internal.h"
40 static int ll_readlink_internal(struct inode *inode,
41 struct ptlrpc_request **request, char **symname)
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;
51 if (lli->lli_symlink_name) {
52 int print_limit = min_t(int, PAGE_SIZE - 128, symlen);
54 *symname = lli->lli_symlink_name;
55 /* If the total CDEBUG() size is larger than a page, it
56 * will print a warning to the console, avoid this by
57 * printing just the last part of the symlink.
59 CDEBUG(D_INODE, "using cached symlink %s%.*s, len = %d\n",
60 print_limit < symlen ? "..." : "", print_limit,
61 (*symname) + symlen - print_limit, symlen);
65 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, symlen,
66 LUSTRE_OPC_ANY, NULL);
68 return PTR_ERR(op_data);
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);
75 CERROR("%s: inode "DFID": rc = %d\n",
76 ll_get_fsname(inode->i_sb, NULL, 0),
77 PFID(ll_inode2fid(inode)), rc);
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");
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,
98 *symname = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_MD);
100 strnlen(*symname, symlen) != symlen - 1) {
101 /* not full/NULL terminated */
102 CERROR("inode %lu: symlink not NULL terminated string of length %d\n",
103 inode->i_ino, symlen - 1);
108 lli->lli_symlink_name = kzalloc(symlen, GFP_NOFS);
109 /* do not return an error if we cannot cache the symlink locally */
110 if (lli->lli_symlink_name) {
111 memcpy(lli->lli_symlink_name, *symname, symlen);
112 *symname = lli->lli_symlink_name;
120 static void ll_put_link(void *p)
122 ptlrpc_req_finished(p);
125 static const char *ll_get_link(struct dentry *dentry,
127 struct delayed_call *done)
129 struct ptlrpc_request *request = NULL;
131 char *symname = NULL;
133 return ERR_PTR(-ECHILD);
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);
140 ptlrpc_req_finished(request);
144 /* symname may contain a pointer to the request message buffer,
145 * we delay request releasing then.
147 set_delayed_call(done, ll_put_link, request);
151 const 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 .setxattr = generic_setxattr,
158 .getxattr = generic_getxattr,
159 .listxattr = ll_listxattr,
160 .removexattr = generic_removexattr,