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.
22 #define DEBUG_SUBSYSTEM S_LLITE
24 #include <linux/lustre_lite.h>
26 static int ll_readlink_internal(struct inode *inode,
27 struct ptlrpc_request **request, char **symname)
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;
35 if (lli->lli_symlink_name) {
36 *symname = lli->lli_symlink_name;
37 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
41 rc = mdc_getattr(&sbi->ll_mdc_conn, inode->i_ino, S_IFLNK,
42 OBD_MD_LINKNAME, len, request);
44 CERROR("inode "LPD64": rc = %d\n", inode->i_ino, rc);
48 *symname = lustre_msg_buf((*request)->rq_repmsg, 1);
50 OBD_ALLOC(lli->lli_symlink_name, len);
51 /* do not return an error if we cannot cache the symlink locally */
52 if (lli->lli_symlink_name)
53 memcpy(lli->lli_symlink_name, *symname, len);
58 static int ll_readlink(struct dentry *dentry, char *buffer, int buflen)
60 struct inode *inode = dentry->d_inode;
61 struct ll_inode_info *lli = ll_i2info(inode);
62 struct ptlrpc_request *request;
67 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
68 down(&lli->lli_open_sem);
69 rc = ll_readlink_internal(inode, &request, &symname);
73 rc = vfs_readlink(dentry, buffer, buflen, symname);
75 up(&lli->lli_open_sem);
76 ptlrpc_free_req(request);
81 static int ll_follow_link(struct dentry *dentry, struct nameidata *nd)
83 struct inode *inode = dentry->d_inode;
84 struct ll_inode_info *lli = ll_i2info(inode);
85 struct ptlrpc_request *request;
90 down(&lli->lli_open_sem);
91 rc = ll_readlink_internal(inode, &request, &symname);
95 rc = vfs_follow_link(nd, symname);
97 up(&lli->lli_open_sem);
98 ptlrpc_free_req(request);
103 extern int ll_setattr(struct dentry *de, struct iattr *attr);
104 struct inode_operations ll_fast_symlink_inode_operations = {
105 readlink: ll_readlink,
107 follow_link: ll_follow_link