1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #include <linux/stat.h>
25 #include <linux/smp_lock.h>
26 #include <linux/version.h>
27 #define DEBUG_SUBSYSTEM S_LLITE
29 #include <linux/lustre_lite.h>
30 #include "llite_internal.h"
32 static int ll_readlink_internal(struct inode *inode,
33 struct ptlrpc_request **request,
36 struct ll_inode_info *lli = ll_i2info(inode);
37 struct ll_sb_info *sbi = ll_i2sbi(inode);
39 struct mds_body *body;
40 int rc, symlen = inode->i_size + 1;
45 if (lli->lli_symlink_name) {
46 *symname = lli->lli_symlink_name;
47 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
51 ll_inode2id(&id, inode);
52 rc = md_getattr(sbi->ll_md_exp, &id, OBD_MD_LINKNAME, NULL, NULL, 0,
57 CERROR("inode %lu: rc = %d\n", inode->i_ino, rc);
61 body = lustre_msg_buf ((*request)->rq_repmsg, 0, sizeof (*body));
62 LASSERT (body != NULL);
63 LASSERT_REPSWABBED (*request, 0);
65 if ((body->valid & OBD_MD_LINKNAME) == 0) {
66 CERROR ("OBD_MD_LINKNAME not set on reply\n");
67 GOTO (failed, rc = -EPROTO);
70 LASSERT (symlen != 0);
71 if (body->eadatasize != symlen) {
72 CERROR ("inode %lu: symlink length %d not expected %d\n",
73 inode->i_ino, body->eadatasize - 1, symlen - 1);
74 GOTO (failed, rc = -EPROTO);
77 *symname = lustre_msg_buf ((*request)->rq_repmsg, 1, symlen);
78 if (*symname == NULL ||
79 strnlen (*symname, symlen) != symlen - 1) {
80 /* not full/NULL terminated */
81 CERROR ("inode %lu: symlink not NULL terminated string"
82 "of length %d\n", inode->i_ino, symlen - 1);
83 GOTO (failed, rc = -EPROTO);
86 OBD_ALLOC(lli->lli_symlink_name, symlen);
87 /* do not return an error if we cannot cache the symlink locally */
88 if (lli->lli_symlink_name)
89 memcpy(lli->lli_symlink_name, *symname, symlen);
94 ptlrpc_req_finished (*request);
98 static int ll_readlink(struct dentry *dentry, char *buffer, int buflen)
100 struct inode *inode = dentry->d_inode;
101 struct ll_inode_info *lli = ll_i2info(inode);
102 struct ptlrpc_request *request;
107 CDEBUG(D_VFSTRACE, "VFS Op\n");
108 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
109 down(&lli->lli_open_sem);
110 rc = ll_readlink_internal(inode, &request, &symname);
114 rc = vfs_readlink(dentry, buffer, buflen, symname);
115 ptlrpc_req_finished(request);
117 up(&lli->lli_open_sem);
121 static int ll_follow_link(struct dentry *dentry, struct nameidata *nd)
123 struct inode *inode = dentry->d_inode;
124 struct ll_inode_info *lli = ll_i2info(inode);
125 struct lookup_intent *it = ll_nd2it(nd);
126 struct ptlrpc_request *request;
133 int mode = it->it_create_mode;
135 ll_intent_release(it);
137 it->it_create_mode = mode;
140 CDEBUG(D_VFSTRACE, "VFS Op\n");
141 down(&lli->lli_open_sem);
142 rc = ll_readlink_internal(inode, &request, &symname);
143 up(&lli->lli_open_sem);
145 path_release(nd); /* Kernel assumes that ->follow_link()
146 releases nameidata on error */
150 rc = vfs_follow_link(nd, symname);
151 ptlrpc_req_finished(request);
156 struct inode_operations ll_fast_symlink_inode_operations = {
157 .readlink = ll_readlink,
158 .setattr = ll_setattr,
159 .follow_link = ll_follow_link,
160 .setxattr = ll_setxattr,
161 .getxattr = ll_getxattr,
162 .listxattr = ll_listxattr,
163 .removexattr = ll_removexattr,
164 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
165 .revalidate_it = ll_inode_revalidate_it
167 .getattr = ll_getattr