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, len = inode->i_size + 1;
40 CHECK_MOUNT_EPOCH(inode);
42 if (lli->lli_symlink_name) {
43 *symname = lli->lli_symlink_name;
44 CDEBUG(D_INODE, "using cached symlink %s\n", *symname);
48 rc = mdc_getattr(&sbi->ll_mdc_conn, inode->i_ino, S_IFLNK,
49 OBD_MD_LINKNAME, len, request);
51 CERROR("inode "LPD64": rc = %d\n", inode->i_ino, rc);
55 *symname = lustre_msg_buf((*request)->rq_repmsg, 1);
57 OBD_ALLOC(lli->lli_symlink_name, len);
58 /* do not return an error if we cannot cache the symlink locally */
59 if (lli->lli_symlink_name)
60 memcpy(lli->lli_symlink_name, *symname, len);
65 static int ll_readlink(struct dentry *dentry, char *buffer, int buflen)
67 struct inode *inode = dentry->d_inode;
68 struct ll_inode_info *lli = ll_i2info(inode);
69 struct ptlrpc_request *request;
74 CHECK_MOUNT_EPOCH(inode);
76 /* on symlinks lli_open_sem protects lli_symlink_name allocation/data */
77 down(&lli->lli_open_sem);
78 rc = ll_readlink_internal(inode, &request, &symname);
82 rc = vfs_readlink(dentry, buffer, buflen, symname);
84 up(&lli->lli_open_sem);
85 ptlrpc_req_finished(request);
90 static int ll_follow_link(struct dentry *dentry, struct nameidata *nd)
92 struct inode *inode = dentry->d_inode;
93 struct ll_inode_info *lli = ll_i2info(inode);
94 struct ptlrpc_request *request;
99 CHECK_MOUNT_EPOCH(inode);
101 down(&lli->lli_open_sem);
102 rc = ll_readlink_internal(inode, &request, &symname);
106 rc = vfs_follow_link(nd, symname);
108 up(&lli->lli_open_sem);
109 ptlrpc_req_finished(request);
114 extern int ll_setattr(struct dentry *de, struct iattr *attr);
115 struct inode_operations ll_fast_symlink_inode_operations = {
116 readlink: ll_readlink,
118 follow_link: ll_follow_link