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 #define DEBUG_SUBSYSTEM S_LLITE
28 #include <linux/lustre_lite.h>
30 static int ll_readlink_internal(struct inode *inode,
31 struct ptlrpc_request **request, char **symname)
33 struct ll_inode_info *lli = ll_i2info(inode);
34 struct ll_sb_info *sbi = ll_i2sbi(inode);
35 int rc, symlen = inode->i_size + 1;
40 if (lli->lli_symlink_name) {
41 *symname = lli->lli_symlink_name;
42 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
46 rc = mdc_getattr(&sbi->ll_mdc_conn, inode->i_ino, S_IFLNK,
47 OBD_MD_LINKNAME, symlen, request);
49 CERROR("inode %lu: rc = %d\n", inode->i_ino, rc);
53 *symname = lustre_msg_buf((*request)->rq_repmsg, 1);
55 OBD_ALLOC(lli->lli_symlink_name, symlen);
56 /* do not return an error if we cannot cache the symlink locally */
57 if (lli->lli_symlink_name)
58 memcpy(lli->lli_symlink_name, *symname, symlen);
63 static int ll_readlink(struct dentry *dentry, char *buffer, int buflen)
65 struct inode *inode = dentry->d_inode;
66 struct ll_inode_info *lli = ll_i2info(inode);
67 struct ptlrpc_request *request;
72 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
73 down(&lli->lli_open_sem);
74 rc = ll_readlink_internal(inode, &request, &symname);
78 rc = vfs_readlink(dentry, buffer, buflen, symname);
80 up(&lli->lli_open_sem);
81 ptlrpc_req_finished(request);
86 static int ll_follow_link(struct dentry *dentry, struct nameidata *nd,
87 struct lookup_intent *it)
89 struct inode *inode = dentry->d_inode;
90 struct ll_inode_info *lli = ll_i2info(inode);
91 struct ptlrpc_request *request;
100 ll_intent_release(dentry, it);
101 down(&lli->lli_open_sem);
106 rc = ll_readlink_internal(inode, &request, &symname);
110 rc = vfs_follow_link_it(nd, symname, it);
112 up(&lli->lli_open_sem);
113 ptlrpc_req_finished(request);
118 extern int ll_setattr(struct dentry *de, struct iattr *attr);
119 struct inode_operations ll_fast_symlink_inode_operations = {
120 readlink: ll_readlink,
122 follow_link2: ll_follow_link