Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/9p/vfs_inode.c |
| 3 | * |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 4 | * This file contains vfs inode ops for the 9P2000 protocol. |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
| 7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Eric Van Hensbergen | 42e8c50 | 2006-03-25 03:07:28 -0800 | [diff] [blame] | 10 | * it under the terms of the GNU General Public License version 2 |
| 11 | * as published by the Free Software Foundation. |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to: |
| 20 | * Free Software Foundation |
| 21 | * 51 Franklin Street, Fifth Floor |
| 22 | * Boston, MA 02111-1301 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/file.h> |
| 30 | #include <linux/pagemap.h> |
| 31 | #include <linux/stat.h> |
| 32 | #include <linux/string.h> |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 33 | #include <linux/inet.h> |
| 34 | #include <linux/namei.h> |
| 35 | #include <linux/idr.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 36 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame] | 38 | #include <linux/xattr.h> |
Aneesh Kumar K.V | 85ff872 | 2010-09-28 00:27:39 +0530 | [diff] [blame] | 39 | #include <linux/posix_acl.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 40 | #include <net/9p/9p.h> |
| 41 | #include <net/9p/client.h> |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 42 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 43 | #include "v9fs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 44 | #include "v9fs_vfs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 45 | #include "fid.h" |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 46 | #include "cache.h" |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame] | 47 | #include "xattr.h" |
Aneesh Kumar K.V | 85ff872 | 2010-09-28 00:27:39 +0530 | [diff] [blame] | 48 | #include "acl.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 49 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 50 | static const struct inode_operations v9fs_dir_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 51 | static const struct inode_operations v9fs_dir_inode_operations_dotu; |
| 52 | static const struct inode_operations v9fs_dir_inode_operations_dotl; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 53 | static const struct inode_operations v9fs_file_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 54 | static const struct inode_operations v9fs_file_inode_operations_dotl; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 55 | static const struct inode_operations v9fs_symlink_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 56 | static const struct inode_operations v9fs_symlink_inode_operations_dotl; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 57 | |
Aneesh Kumar K.V | f5fc614 | 2010-10-12 13:02:25 +0530 | [diff] [blame] | 58 | static int |
| 59 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, |
| 60 | dev_t rdev); |
| 61 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 62 | /** |
| 63 | * unixmode2p9mode - convert unix mode bits to plan 9 |
| 64 | * @v9ses: v9fs session information |
| 65 | * @mode: mode to convert |
| 66 | * |
| 67 | */ |
| 68 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 69 | static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 70 | { |
| 71 | int res; |
| 72 | res = mode & 0777; |
| 73 | if (S_ISDIR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 74 | res |= P9_DMDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 75 | if (v9fs_proto_dotu(v9ses)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 76 | if (S_ISLNK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 77 | res |= P9_DMSYMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 78 | if (v9ses->nodev == 0) { |
| 79 | if (S_ISSOCK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 80 | res |= P9_DMSOCKET; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 81 | if (S_ISFIFO(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 82 | res |= P9_DMNAMEDPIPE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 83 | if (S_ISBLK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 84 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 85 | if (S_ISCHR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 86 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | if ((mode & S_ISUID) == S_ISUID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 90 | res |= P9_DMSETUID; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 91 | if ((mode & S_ISGID) == S_ISGID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 92 | res |= P9_DMSETGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 93 | if ((mode & S_ISVTX) == S_ISVTX) |
| 94 | res |= P9_DMSETVTX; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 95 | if ((mode & P9_DMLINK)) |
| 96 | res |= P9_DMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | return res; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * p9mode2unixmode- convert plan9 mode bits to unix mode bits |
| 104 | * @v9ses: v9fs session information |
| 105 | * @mode: mode to convert |
| 106 | * |
| 107 | */ |
| 108 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 109 | static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 110 | { |
| 111 | int res; |
| 112 | |
| 113 | res = mode & 0777; |
| 114 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 115 | if ((mode & P9_DMDIR) == P9_DMDIR) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 116 | res |= S_IFDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 117 | else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses))) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 118 | res |= S_IFLNK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 119 | else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 120 | && (v9ses->nodev == 0)) |
| 121 | res |= S_IFSOCK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 122 | else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 123 | && (v9ses->nodev == 0)) |
| 124 | res |= S_IFIFO; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 125 | else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 126 | && (v9ses->nodev == 0)) |
| 127 | res |= S_IFBLK; |
| 128 | else |
| 129 | res |= S_IFREG; |
| 130 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 131 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 132 | if ((mode & P9_DMSETUID) == P9_DMSETUID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 133 | res |= S_ISUID; |
| 134 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 135 | if ((mode & P9_DMSETGID) == P9_DMSETGID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 136 | res |= S_ISGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 137 | |
| 138 | if ((mode & P9_DMSETVTX) == P9_DMSETVTX) |
| 139 | res |= S_ISVTX; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return res; |
| 143 | } |
| 144 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 145 | /** |
| 146 | * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits |
| 147 | * @uflags: flags to convert |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 148 | * @extended: if .u extensions are active |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 149 | */ |
| 150 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 151 | int v9fs_uflags2omode(int uflags, int extended) |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 152 | { |
| 153 | int ret; |
| 154 | |
| 155 | ret = 0; |
| 156 | switch (uflags&3) { |
| 157 | default: |
| 158 | case O_RDONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 159 | ret = P9_OREAD; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 160 | break; |
| 161 | |
| 162 | case O_WRONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 163 | ret = P9_OWRITE; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 164 | break; |
| 165 | |
| 166 | case O_RDWR: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 167 | ret = P9_ORDWR; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 168 | break; |
| 169 | } |
| 170 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 171 | if (uflags & O_TRUNC) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 172 | ret |= P9_OTRUNC; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 173 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 174 | if (extended) { |
| 175 | if (uflags & O_EXCL) |
| 176 | ret |= P9_OEXCL; |
| 177 | |
| 178 | if (uflags & O_APPEND) |
| 179 | ret |= P9_OAPPEND; |
| 180 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 185 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 186 | * v9fs_blank_wstat - helper function to setup a 9P stat structure |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 187 | * @wstat: structure to initialize |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 188 | * |
| 189 | */ |
| 190 | |
M. Mohan Kumar | 7a4439c | 2010-02-08 15:36:48 -0600 | [diff] [blame] | 191 | void |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 192 | v9fs_blank_wstat(struct p9_wstat *wstat) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 193 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 194 | wstat->type = ~0; |
| 195 | wstat->dev = ~0; |
| 196 | wstat->qid.type = ~0; |
| 197 | wstat->qid.version = ~0; |
| 198 | *((long long *)&wstat->qid.path) = ~0; |
| 199 | wstat->mode = ~0; |
| 200 | wstat->atime = ~0; |
| 201 | wstat->mtime = ~0; |
| 202 | wstat->length = ~0; |
| 203 | wstat->name = NULL; |
| 204 | wstat->uid = NULL; |
| 205 | wstat->gid = NULL; |
| 206 | wstat->muid = NULL; |
| 207 | wstat->n_uid = ~0; |
| 208 | wstat->n_gid = ~0; |
| 209 | wstat->n_muid = ~0; |
| 210 | wstat->extension = NULL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 213 | #ifdef CONFIG_9P_FSCACHE |
| 214 | /** |
| 215 | * v9fs_alloc_inode - helper function to allocate an inode |
| 216 | * This callback is executed before setting up the inode so that we |
| 217 | * can associate a vcookie with each inode. |
| 218 | * |
| 219 | */ |
| 220 | |
| 221 | struct inode *v9fs_alloc_inode(struct super_block *sb) |
| 222 | { |
| 223 | struct v9fs_cookie *vcookie; |
| 224 | vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache, |
| 225 | GFP_KERNEL); |
| 226 | if (!vcookie) |
| 227 | return NULL; |
| 228 | |
| 229 | vcookie->fscache = NULL; |
| 230 | vcookie->qid = NULL; |
| 231 | spin_lock_init(&vcookie->lock); |
| 232 | return &vcookie->inode; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * v9fs_destroy_inode - destroy an inode |
| 237 | * |
| 238 | */ |
| 239 | |
| 240 | void v9fs_destroy_inode(struct inode *inode) |
| 241 | { |
| 242 | kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode)); |
| 243 | } |
| 244 | #endif |
| 245 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 246 | /** |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 247 | * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a |
| 248 | * new file system object. This checks the S_ISGID to determine the owning |
| 249 | * group of the new file system object. |
| 250 | */ |
| 251 | |
| 252 | static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode) |
| 253 | { |
| 254 | BUG_ON(dir_inode == NULL); |
| 255 | |
| 256 | if (dir_inode->i_mode & S_ISGID) { |
| 257 | /* set_gid bit is set.*/ |
| 258 | return dir_inode->i_gid; |
| 259 | } |
| 260 | return current_fsgid(); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * v9fs_dentry_from_dir_inode - helper function to get the dentry from |
| 265 | * dir inode. |
| 266 | * |
| 267 | */ |
| 268 | |
Eric Van Hensbergen | ea137533 | 2010-07-27 14:49:43 -0500 | [diff] [blame] | 269 | static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode) |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 270 | { |
| 271 | struct dentry *dentry; |
| 272 | |
| 273 | spin_lock(&dcache_lock); |
| 274 | /* Directory should have only one entry. */ |
| 275 | BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry)); |
| 276 | dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); |
| 277 | spin_unlock(&dcache_lock); |
| 278 | return dentry; |
| 279 | } |
| 280 | |
| 281 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 282 | * v9fs_get_inode - helper function to setup an inode |
| 283 | * @sb: superblock |
| 284 | * @mode: mode to setup inode with |
| 285 | * |
| 286 | */ |
| 287 | |
| 288 | struct inode *v9fs_get_inode(struct super_block *sb, int mode) |
| 289 | { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 290 | int err; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 291 | struct inode *inode; |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 292 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 293 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 294 | P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 295 | |
| 296 | inode = new_inode(sb); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 297 | if (!inode) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 298 | P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); |
Abhishek Kulkarni | 48559b4c | 2009-08-17 16:32:18 -0500 | [diff] [blame] | 299 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 300 | } |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 301 | |
Dmitry Monakhov | 217f206 | 2010-03-04 17:30:57 +0300 | [diff] [blame] | 302 | inode_init_owner(inode, NULL, mode); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 303 | inode->i_blocks = 0; |
| 304 | inode->i_rdev = 0; |
| 305 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 306 | inode->i_mapping->a_ops = &v9fs_addr_operations; |
| 307 | |
| 308 | switch (mode & S_IFMT) { |
| 309 | case S_IFIFO: |
| 310 | case S_IFBLK: |
| 311 | case S_IFCHR: |
| 312 | case S_IFSOCK: |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 313 | if (v9fs_proto_dotl(v9ses)) { |
| 314 | inode->i_op = &v9fs_file_inode_operations_dotl; |
| 315 | inode->i_fop = &v9fs_file_operations_dotl; |
| 316 | } else if (v9fs_proto_dotu(v9ses)) { |
| 317 | inode->i_op = &v9fs_file_inode_operations; |
| 318 | inode->i_fop = &v9fs_file_operations; |
| 319 | } else { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 320 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 321 | "special files without extended mode\n"); |
| 322 | err = -EINVAL; |
| 323 | goto error; |
| 324 | } |
| 325 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 326 | break; |
| 327 | case S_IFREG: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 328 | if (v9fs_proto_dotl(v9ses)) { |
| 329 | inode->i_op = &v9fs_file_inode_operations_dotl; |
| 330 | inode->i_fop = &v9fs_file_operations_dotl; |
| 331 | } else { |
| 332 | inode->i_op = &v9fs_file_inode_operations; |
| 333 | inode->i_fop = &v9fs_file_operations; |
| 334 | } |
| 335 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 336 | break; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 337 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 338 | case S_IFLNK: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 339 | if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) { |
| 340 | P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with " |
| 341 | "legacy protocol.\n"); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 342 | err = -EINVAL; |
| 343 | goto error; |
| 344 | } |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 345 | |
| 346 | if (v9fs_proto_dotl(v9ses)) |
| 347 | inode->i_op = &v9fs_symlink_inode_operations_dotl; |
| 348 | else |
| 349 | inode->i_op = &v9fs_symlink_inode_operations; |
| 350 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 351 | break; |
| 352 | case S_IFDIR: |
| 353 | inc_nlink(inode); |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 354 | if (v9fs_proto_dotl(v9ses)) |
| 355 | inode->i_op = &v9fs_dir_inode_operations_dotl; |
| 356 | else if (v9fs_proto_dotu(v9ses)) |
| 357 | inode->i_op = &v9fs_dir_inode_operations_dotu; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 358 | else |
| 359 | inode->i_op = &v9fs_dir_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 360 | |
| 361 | if (v9fs_proto_dotl(v9ses)) |
| 362 | inode->i_fop = &v9fs_dir_operations_dotl; |
| 363 | else |
| 364 | inode->i_fop = &v9fs_dir_operations; |
| 365 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 366 | break; |
| 367 | default: |
| 368 | P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", |
| 369 | mode, mode & S_IFMT); |
| 370 | err = -EINVAL; |
| 371 | goto error; |
| 372 | } |
| 373 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 374 | return inode; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 375 | |
| 376 | error: |
| 377 | iput(inode); |
| 378 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 381 | /* |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 382 | static struct v9fs_fid* |
| 383 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) |
| 384 | { |
| 385 | int err; |
Mika Kukkonen | 736c4b8 | 2006-12-06 20:36:29 -0800 | [diff] [blame] | 386 | int nfid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 387 | struct v9fs_fid *ret; |
| 388 | struct v9fs_fcall *fcall; |
| 389 | |
| 390 | nfid = v9fs_get_idpool(&v9ses->fidpool); |
| 391 | if (nfid < 0) { |
| 392 | eprintk(KERN_WARNING, "no free fids available\n"); |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 393 | return ERR_PTR(-ENOSPC); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name, |
| 397 | &fcall); |
| 398 | |
| 399 | if (err < 0) { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 400 | if (fcall && fcall->id == RWALK) |
| 401 | goto clunk_fid; |
| 402 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 403 | PRINT_FCALL_ERROR("walk error", fcall); |
| 404 | v9fs_put_idpool(nfid, &v9ses->fidpool); |
| 405 | goto error; |
| 406 | } |
| 407 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 408 | kfree(fcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 409 | fcall = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 410 | ret = v9fs_fid_create(v9ses, nfid); |
| 411 | if (!ret) { |
| 412 | err = -ENOMEM; |
| 413 | goto clunk_fid; |
| 414 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 415 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 416 | err = v9fs_fid_insert(ret, dentry); |
| 417 | if (err < 0) { |
| 418 | v9fs_fid_destroy(ret); |
| 419 | goto clunk_fid; |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 420 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 421 | |
| 422 | return ret; |
| 423 | |
| 424 | clunk_fid: |
| 425 | v9fs_t_clunk(v9ses, nfid); |
| 426 | |
| 427 | error: |
| 428 | kfree(fcall); |
| 429 | return ERR_PTR(err); |
| 430 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 431 | */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 432 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * v9fs_clear_inode - release an inode |
| 436 | * @inode: inode to release |
| 437 | * |
| 438 | */ |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 439 | void v9fs_evict_inode(struct inode *inode) |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 440 | { |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 441 | truncate_inode_pages(inode->i_mapping, 0); |
| 442 | end_writeback(inode); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 443 | filemap_fdatawrite(inode->i_mapping); |
| 444 | |
| 445 | #ifdef CONFIG_9P_FSCACHE |
| 446 | v9fs_cache_inode_put_cookie(inode); |
| 447 | #endif |
| 448 | } |
| 449 | |
Latchesar Ionkov | 5174fda | 2006-03-25 03:07:25 -0800 | [diff] [blame] | 450 | static struct inode * |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 451 | v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 452 | struct super_block *sb) |
| 453 | { |
| 454 | int err, umode; |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 455 | struct inode *ret = NULL; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 456 | struct p9_wstat *st; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 457 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 458 | st = p9_client_stat(fid); |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 459 | if (IS_ERR(st)) |
| 460 | return ERR_CAST(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 461 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 462 | umode = p9mode2unixmode(v9ses, st->mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 463 | ret = v9fs_get_inode(sb, umode); |
| 464 | if (IS_ERR(ret)) { |
| 465 | err = PTR_ERR(ret); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 466 | goto error; |
| 467 | } |
| 468 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 469 | v9fs_stat2inode(st, ret, sb); |
| 470 | ret->i_ino = v9fs_qid2ino(&st->qid); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 471 | |
| 472 | #ifdef CONFIG_9P_FSCACHE |
| 473 | v9fs_vcookie_set_qid(ret, &st->qid); |
| 474 | v9fs_cache_inode_get_cookie(ret); |
| 475 | #endif |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 476 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 477 | kfree(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 478 | return ret; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 479 | error: |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 480 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 481 | kfree(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 482 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 485 | static struct inode * |
| 486 | v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 487 | struct super_block *sb) |
| 488 | { |
| 489 | struct inode *ret = NULL; |
| 490 | int err; |
| 491 | struct p9_stat_dotl *st; |
| 492 | |
| 493 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); |
| 494 | if (IS_ERR(st)) |
| 495 | return ERR_CAST(st); |
| 496 | |
| 497 | ret = v9fs_get_inode(sb, st->st_mode); |
| 498 | if (IS_ERR(ret)) { |
| 499 | err = PTR_ERR(ret); |
| 500 | goto error; |
| 501 | } |
| 502 | |
| 503 | v9fs_stat2inode_dotl(st, ret); |
| 504 | ret->i_ino = v9fs_qid2ino(&st->qid); |
| 505 | #ifdef CONFIG_9P_FSCACHE |
| 506 | v9fs_vcookie_set_qid(ret, &st->qid); |
| 507 | v9fs_cache_inode_get_cookie(ret); |
| 508 | #endif |
Aneesh Kumar K.V | 85ff872 | 2010-09-28 00:27:39 +0530 | [diff] [blame] | 509 | err = v9fs_get_acl(ret, fid); |
| 510 | if (err) { |
| 511 | iput(ret); |
| 512 | goto error; |
| 513 | } |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 514 | kfree(st); |
| 515 | return ret; |
| 516 | error: |
| 517 | kfree(st); |
| 518 | return ERR_PTR(err); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * v9fs_inode_from_fid - Helper routine to populate an inode by |
| 523 | * issuing a attribute request |
| 524 | * @v9ses: session information |
| 525 | * @fid: fid to issue attribute request for |
| 526 | * @sb: superblock on which to create inode |
| 527 | * |
| 528 | */ |
| 529 | static inline struct inode * |
| 530 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 531 | struct super_block *sb) |
| 532 | { |
| 533 | if (v9fs_proto_dotl(v9ses)) |
| 534 | return v9fs_inode_dotl(v9ses, fid, sb); |
| 535 | else |
| 536 | return v9fs_inode(v9ses, fid, sb); |
| 537 | } |
| 538 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 539 | /** |
| 540 | * v9fs_remove - helper function to remove files and directories |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 541 | * @dir: directory inode that is being deleted |
| 542 | * @file: dentry that is being deleted |
| 543 | * @rmdir: removing a directory |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 544 | * |
| 545 | */ |
| 546 | |
| 547 | static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) |
| 548 | { |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 549 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 550 | struct inode *file_inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 551 | struct p9_fid *v9fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 552 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 553 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 554 | rmdir); |
| 555 | |
| 556 | file_inode = file->d_inode; |
Latchesar Ionkov | c959df9 | 2007-04-23 14:41:11 -0700 | [diff] [blame] | 557 | v9fid = v9fs_fid_clone(file); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 558 | if (IS_ERR(v9fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 559 | return PTR_ERR(v9fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 560 | |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 561 | retval = p9_client_remove(v9fid); |
| 562 | if (!retval) |
| 563 | drop_nlink(file_inode); |
| 564 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 567 | /** |
| 568 | * v9fs_create - Create a file |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 569 | * @v9ses: session information |
| 570 | * @dir: directory that dentry is being created in |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 571 | * @dentry: dentry that is being created |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 572 | * @extension: 9p2000.u extension string to support devices, etc. |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 573 | * @perm: create permissions |
| 574 | * @mode: open mode |
| 575 | * |
| 576 | */ |
| 577 | static struct p9_fid * |
| 578 | v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, |
| 579 | struct dentry *dentry, char *extension, u32 perm, u8 mode) |
| 580 | { |
| 581 | int err; |
| 582 | char *name; |
| 583 | struct p9_fid *dfid, *ofid, *fid; |
| 584 | struct inode *inode; |
| 585 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 586 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 587 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 588 | err = 0; |
| 589 | ofid = NULL; |
| 590 | fid = NULL; |
| 591 | name = (char *) dentry->d_name.name; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 592 | dfid = v9fs_fid_lookup(dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 593 | if (IS_ERR(dfid)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 594 | err = PTR_ERR(dfid); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 595 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 596 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* clone a fid to use for creation */ |
| 600 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 601 | if (IS_ERR(ofid)) { |
| 602 | err = PTR_ERR(ofid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 603 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 604 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | err = p9_client_fcreate(ofid, name, perm, mode, extension); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 608 | if (err < 0) { |
| 609 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 610 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 611 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 612 | |
| 613 | /* now walk from the parent so we can get unopened fid */ |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 614 | fid = p9_client_walk(dfid, 1, &name, 1); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 615 | if (IS_ERR(fid)) { |
| 616 | err = PTR_ERR(fid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 617 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 618 | fid = NULL; |
| 619 | goto error; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 620 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 621 | |
| 622 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 623 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 624 | if (IS_ERR(inode)) { |
| 625 | err = PTR_ERR(inode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 626 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 627 | goto error; |
| 628 | } |
| 629 | |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 630 | if (v9ses->cache) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 631 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 632 | else |
| 633 | dentry->d_op = &v9fs_dentry_operations; |
| 634 | |
| 635 | d_instantiate(dentry, inode); |
Abhishek Kulkarni | 50fb6d2 | 2009-07-19 13:41:57 -0600 | [diff] [blame] | 636 | err = v9fs_fid_add(dentry, fid); |
| 637 | if (err < 0) |
| 638 | goto error; |
| 639 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 640 | return ofid; |
| 641 | |
| 642 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 643 | if (ofid) |
| 644 | p9_client_clunk(ofid); |
| 645 | |
| 646 | if (fid) |
| 647 | p9_client_clunk(fid); |
| 648 | |
| 649 | return ERR_PTR(err); |
| 650 | } |
| 651 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 652 | /** |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 653 | * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol. |
| 654 | * @dir: directory inode that is being created |
| 655 | * @dentry: dentry that is being deleted |
| 656 | * @mode: create permissions |
| 657 | * @nd: path information |
| 658 | * |
| 659 | */ |
| 660 | |
| 661 | static int |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 662 | v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int omode, |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 663 | struct nameidata *nd) |
| 664 | { |
| 665 | int err = 0; |
| 666 | char *name = NULL; |
| 667 | gid_t gid; |
| 668 | int flags; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 669 | mode_t mode; |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 670 | struct v9fs_session_info *v9ses; |
| 671 | struct p9_fid *fid = NULL; |
| 672 | struct p9_fid *dfid, *ofid; |
| 673 | struct file *filp; |
| 674 | struct p9_qid qid; |
| 675 | struct inode *inode; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 676 | struct posix_acl *pacl = NULL, *dacl = NULL; |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 677 | |
| 678 | v9ses = v9fs_inode2v9ses(dir); |
| 679 | if (nd && nd->flags & LOOKUP_OPEN) |
| 680 | flags = nd->intent.open.flags - 1; |
Aneesh Kumar K.V | f5fc614 | 2010-10-12 13:02:25 +0530 | [diff] [blame] | 681 | else { |
| 682 | /* |
| 683 | * create call without LOOKUP_OPEN is due |
| 684 | * to mknod of regular files. So use mknod |
| 685 | * operation. |
| 686 | */ |
| 687 | return v9fs_vfs_mknod_dotl(dir, dentry, omode, 0); |
| 688 | } |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 689 | |
| 690 | name = (char *) dentry->d_name.name; |
| 691 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x " |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 692 | "mode:0x%x\n", name, flags, omode); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 693 | |
| 694 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 695 | if (IS_ERR(dfid)) { |
| 696 | err = PTR_ERR(dfid); |
| 697 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 698 | return err; |
| 699 | } |
| 700 | |
| 701 | /* clone a fid to use for creation */ |
| 702 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 703 | if (IS_ERR(ofid)) { |
| 704 | err = PTR_ERR(ofid); |
| 705 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
| 706 | return err; |
| 707 | } |
| 708 | |
| 709 | gid = v9fs_get_fsgid_for_create(dir); |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 710 | |
| 711 | mode = omode; |
| 712 | /* Update mode based on ACL value */ |
| 713 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); |
| 714 | if (err) { |
| 715 | P9_DPRINTK(P9_DEBUG_VFS, |
| 716 | "Failed to get acl values in creat %d\n", err); |
| 717 | goto error; |
| 718 | } |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 719 | err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid); |
| 720 | if (err < 0) { |
| 721 | P9_DPRINTK(P9_DEBUG_VFS, |
| 722 | "p9_client_open_dotl failed in creat %d\n", |
| 723 | err); |
| 724 | goto error; |
| 725 | } |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 726 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 727 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE || |
| 728 | (nd && nd->flags & LOOKUP_OPEN)) { |
| 729 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 730 | if (IS_ERR(fid)) { |
| 731 | err = PTR_ERR(fid); |
| 732 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 733 | err); |
| 734 | fid = NULL; |
| 735 | goto error; |
| 736 | } |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 737 | |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 738 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 739 | if (IS_ERR(inode)) { |
| 740 | err = PTR_ERR(inode); |
| 741 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 742 | err); |
| 743 | goto error; |
| 744 | } |
Aneesh Kumar K.V | 3c30750 | 2010-08-30 16:04:35 +0000 | [diff] [blame] | 745 | dentry->d_op = &v9fs_cached_dentry_operations; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 746 | d_instantiate(dentry, inode); |
| 747 | err = v9fs_fid_add(dentry, fid); |
| 748 | if (err < 0) |
| 749 | goto error; |
| 750 | /* The fid would get clunked via a dput */ |
| 751 | fid = NULL; |
| 752 | } else { |
| 753 | /* |
| 754 | * Not in cached mode. No need to populate |
| 755 | * inode with stat. We need to get an inode |
| 756 | * so that we can set the acl with dentry |
| 757 | */ |
| 758 | inode = v9fs_get_inode(dir->i_sb, mode); |
| 759 | if (IS_ERR(inode)) { |
| 760 | err = PTR_ERR(inode); |
| 761 | goto error; |
| 762 | } |
Aneesh Kumar K.V | 3c30750 | 2010-08-30 16:04:35 +0000 | [diff] [blame] | 763 | dentry->d_op = &v9fs_dentry_operations; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 764 | d_instantiate(dentry, inode); |
| 765 | } |
| 766 | /* Now set the ACL based on the default value */ |
| 767 | v9fs_set_create_acl(dentry, dacl, pacl); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 768 | |
| 769 | /* if we are opening a file, assign the open fid to the file */ |
| 770 | if (nd && nd->flags & LOOKUP_OPEN) { |
Aneesh Kumar K.V | 877cb3d | 2010-09-22 12:42:30 +0530 | [diff] [blame] | 771 | filp = lookup_instantiate_filp(nd, dentry, generic_file_open); |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 772 | if (IS_ERR(filp)) { |
| 773 | p9_client_clunk(ofid); |
| 774 | return PTR_ERR(filp); |
| 775 | } |
| 776 | filp->private_data = ofid; |
| 777 | } else |
| 778 | p9_client_clunk(ofid); |
| 779 | |
| 780 | return 0; |
| 781 | |
| 782 | error: |
| 783 | if (ofid) |
| 784 | p9_client_clunk(ofid); |
| 785 | if (fid) |
| 786 | p9_client_clunk(fid); |
| 787 | return err; |
| 788 | } |
| 789 | |
| 790 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 791 | * v9fs_vfs_create - VFS hook to create files |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 792 | * @dir: directory inode that is being created |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 793 | * @dentry: dentry that is being deleted |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 794 | * @mode: create permissions |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 795 | * @nd: path information |
| 796 | * |
| 797 | */ |
| 798 | |
| 799 | static int |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 800 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 801 | struct nameidata *nd) |
| 802 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 803 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 804 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 805 | int flags; |
| 806 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 807 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 808 | struct file *filp; |
| 809 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 810 | err = 0; |
| 811 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 812 | v9ses = v9fs_inode2v9ses(dir); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 813 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 814 | if (nd && nd->flags & LOOKUP_OPEN) |
| 815 | flags = nd->intent.open.flags - 1; |
| 816 | else |
| 817 | flags = O_RDWR; |
| 818 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 819 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 820 | v9fs_uflags2omode(flags, |
| 821 | v9fs_proto_dotu(v9ses))); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 822 | if (IS_ERR(fid)) { |
| 823 | err = PTR_ERR(fid); |
| 824 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 825 | goto error; |
| 826 | } |
| 827 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 828 | /* if we are opening a file, assign the open fid to the file */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 829 | if (nd && nd->flags & LOOKUP_OPEN) { |
Aneesh Kumar K.V | 877cb3d | 2010-09-22 12:42:30 +0530 | [diff] [blame] | 830 | filp = lookup_instantiate_filp(nd, dentry, generic_file_open); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 831 | if (IS_ERR(filp)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 832 | err = PTR_ERR(filp); |
| 833 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 834 | } |
| 835 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 836 | filp->private_data = fid; |
| 837 | } else |
| 838 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 839 | |
| 840 | return 0; |
| 841 | |
| 842 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 843 | if (fid) |
| 844 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 845 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 846 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /** |
| 850 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 851 | * @dir: inode that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 852 | * @dentry: dentry that is being unlinked |
| 853 | * @mode: mode for new directory |
| 854 | * |
| 855 | */ |
| 856 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 857 | static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 858 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 859 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 860 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 861 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 862 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 863 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 864 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 865 | err = 0; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 866 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 867 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 868 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD); |
| 869 | if (IS_ERR(fid)) { |
| 870 | err = PTR_ERR(fid); |
| 871 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 872 | } |
| 873 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 874 | if (fid) |
| 875 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 876 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 877 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 878 | } |
| 879 | |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 880 | |
| 881 | /** |
| 882 | * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory |
| 883 | * @dir: inode that is being unlinked |
| 884 | * @dentry: dentry that is being unlinked |
| 885 | * @mode: mode for new directory |
| 886 | * |
| 887 | */ |
| 888 | |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 889 | static int v9fs_vfs_mkdir_dotl(struct inode *dir, |
| 890 | struct dentry *dentry, int omode) |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 891 | { |
| 892 | int err; |
| 893 | struct v9fs_session_info *v9ses; |
| 894 | struct p9_fid *fid = NULL, *dfid = NULL; |
| 895 | gid_t gid; |
| 896 | char *name; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 897 | mode_t mode; |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 898 | struct inode *inode; |
| 899 | struct p9_qid qid; |
| 900 | struct dentry *dir_dentry; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 901 | struct posix_acl *dacl = NULL, *pacl = NULL; |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 902 | |
| 903 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 904 | err = 0; |
| 905 | v9ses = v9fs_inode2v9ses(dir); |
| 906 | |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 907 | omode |= S_IFDIR; |
Harsh Prateek Bora | 7c7298c | 2010-08-18 06:01:52 +0000 | [diff] [blame] | 908 | if (dir->i_mode & S_ISGID) |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 909 | omode |= S_ISGID; |
| 910 | |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 911 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
| 912 | dfid = v9fs_fid_lookup(dir_dentry); |
| 913 | if (IS_ERR(dfid)) { |
| 914 | err = PTR_ERR(dfid); |
| 915 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 916 | dfid = NULL; |
| 917 | goto error; |
| 918 | } |
| 919 | |
| 920 | gid = v9fs_get_fsgid_for_create(dir); |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 921 | mode = omode; |
| 922 | /* Update mode based on ACL value */ |
| 923 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); |
| 924 | if (err) { |
| 925 | P9_DPRINTK(P9_DEBUG_VFS, |
| 926 | "Failed to get acl values in mkdir %d\n", err); |
| 927 | goto error; |
| 928 | } |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 929 | name = (char *) dentry->d_name.name; |
| 930 | err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); |
| 931 | if (err < 0) |
| 932 | goto error; |
| 933 | |
| 934 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 935 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 936 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 937 | if (IS_ERR(fid)) { |
| 938 | err = PTR_ERR(fid); |
| 939 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 940 | err); |
| 941 | fid = NULL; |
| 942 | goto error; |
| 943 | } |
| 944 | |
| 945 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 946 | if (IS_ERR(inode)) { |
| 947 | err = PTR_ERR(inode); |
| 948 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 949 | err); |
| 950 | goto error; |
| 951 | } |
| 952 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 953 | d_instantiate(dentry, inode); |
| 954 | err = v9fs_fid_add(dentry, fid); |
| 955 | if (err < 0) |
| 956 | goto error; |
| 957 | fid = NULL; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 958 | } else { |
| 959 | /* |
| 960 | * Not in cached mode. No need to populate |
| 961 | * inode with stat. We need to get an inode |
| 962 | * so that we can set the acl with dentry |
| 963 | */ |
| 964 | inode = v9fs_get_inode(dir->i_sb, mode); |
| 965 | if (IS_ERR(inode)) { |
| 966 | err = PTR_ERR(inode); |
| 967 | goto error; |
| 968 | } |
| 969 | dentry->d_op = &v9fs_dentry_operations; |
| 970 | d_instantiate(dentry, inode); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 971 | } |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 972 | /* Now set the ACL based on the default value */ |
| 973 | v9fs_set_create_acl(dentry, dacl, pacl); |
| 974 | |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 975 | error: |
| 976 | if (fid) |
| 977 | p9_client_clunk(fid); |
| 978 | return err; |
| 979 | } |
| 980 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 981 | /** |
| 982 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode |
| 983 | * @dir: inode that is being walked from |
| 984 | * @dentry: dentry that is being walked to? |
| 985 | * @nameidata: path data |
| 986 | * |
| 987 | */ |
| 988 | |
| 989 | static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, |
| 990 | struct nameidata *nameidata) |
| 991 | { |
| 992 | struct super_block *sb; |
| 993 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 994 | struct p9_fid *dfid, *fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 995 | struct inode *inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 996 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 997 | int result = 0; |
| 998 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 999 | P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 1000 | dir, dentry->d_name.name, dentry, nameidata); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1001 | |
Sripathi Kodi | 11e9b49 | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 1002 | if (dentry->d_name.len > NAME_MAX) |
| 1003 | return ERR_PTR(-ENAMETOOLONG); |
| 1004 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1005 | sb = dir->i_sb; |
| 1006 | v9ses = v9fs_inode2v9ses(dir); |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 1007 | /* We can walk d_parent because we hold the dir->i_mutex */ |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1008 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 1009 | if (IS_ERR(dfid)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 1010 | return ERR_CAST(dfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1011 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1012 | name = (char *) dentry->d_name.name; |
| 1013 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 1014 | if (IS_ERR(fid)) { |
| 1015 | result = PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1016 | if (result == -ENOENT) { |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 1017 | inode = NULL; |
| 1018 | goto inst_out; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1019 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1020 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1021 | return ERR_PTR(result); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1024 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 1025 | if (IS_ERR(inode)) { |
| 1026 | result = PTR_ERR(inode); |
| 1027 | inode = NULL; |
| 1028 | goto error; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1031 | result = v9fs_fid_add(dentry, fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1032 | if (result < 0) |
Aneesh Kumar K.V | 9856af8 | 2010-09-22 12:24:23 +0530 | [diff] [blame] | 1033 | goto error_iput; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1034 | |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 1035 | inst_out: |
| 1036 | if (v9ses->cache) |
Eric Van Hensbergen | e03abc0 | 2007-02-11 13:21:39 -0600 | [diff] [blame] | 1037 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 1038 | else |
| 1039 | dentry->d_op = &v9fs_dentry_operations; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1040 | |
| 1041 | d_add(dentry, inode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1042 | return NULL; |
| 1043 | |
Aneesh Kumar K.V | 9856af8 | 2010-09-22 12:24:23 +0530 | [diff] [blame] | 1044 | error_iput: |
| 1045 | iput(inode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1046 | error: |
Julien Brunel | 62aa528 | 2008-09-24 16:22:22 -0500 | [diff] [blame] | 1047 | p9_client_clunk(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1048 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1049 | return ERR_PTR(result); |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * v9fs_vfs_unlink - VFS unlink hook to delete an inode |
| 1054 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1055 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1056 | * |
| 1057 | */ |
| 1058 | |
| 1059 | static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) |
| 1060 | { |
| 1061 | return v9fs_remove(i, d, 0); |
| 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * v9fs_vfs_rmdir - VFS unlink hook to delete a directory |
| 1066 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1067 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1068 | * |
| 1069 | */ |
| 1070 | |
| 1071 | static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) |
| 1072 | { |
| 1073 | return v9fs_remove(i, d, 1); |
| 1074 | } |
| 1075 | |
| 1076 | /** |
| 1077 | * v9fs_vfs_rename - VFS hook to rename an inode |
| 1078 | * @old_dir: old dir inode |
| 1079 | * @old_dentry: old dentry |
| 1080 | * @new_dir: new dir inode |
| 1081 | * @new_dentry: new dentry |
| 1082 | * |
| 1083 | */ |
| 1084 | |
| 1085 | static int |
| 1086 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1087 | struct inode *new_dir, struct dentry *new_dentry) |
| 1088 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1089 | struct inode *old_inode; |
| 1090 | struct v9fs_session_info *v9ses; |
| 1091 | struct p9_fid *oldfid; |
| 1092 | struct p9_fid *olddirfid; |
| 1093 | struct p9_fid *newdirfid; |
| 1094 | struct p9_wstat wstat; |
| 1095 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1096 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1097 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1098 | retval = 0; |
| 1099 | old_inode = old_dentry->d_inode; |
| 1100 | v9ses = v9fs_inode2v9ses(old_inode); |
| 1101 | oldfid = v9fs_fid_lookup(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1102 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1103 | return PTR_ERR(oldfid); |
| 1104 | |
| 1105 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1106 | if (IS_ERR(olddirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1107 | retval = PTR_ERR(olddirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1108 | goto done; |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1112 | if (IS_ERR(newdirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1113 | retval = PTR_ERR(newdirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1114 | goto clunk_olddir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 1117 | down_write(&v9ses->rename_sem); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1118 | if (v9fs_proto_dotl(v9ses)) { |
| 1119 | retval = p9_client_rename(oldfid, newdirfid, |
| 1120 | (char *) new_dentry->d_name.name); |
| 1121 | if (retval != -ENOSYS) |
| 1122 | goto clunk_newdir; |
| 1123 | } |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 1124 | if (old_dentry->d_parent != new_dentry->d_parent) { |
| 1125 | /* |
| 1126 | * 9P .u can only handle file rename in the same directory |
| 1127 | */ |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1128 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1129 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 1130 | "old dir and new dir are different\n"); |
Eric Van Hensbergen | 621997c | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 1131 | retval = -EXDEV; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1132 | goto clunk_newdir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1133 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1134 | v9fs_blank_wstat(&wstat); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1135 | wstat.muid = v9ses->uname; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1136 | wstat.name = (char *) new_dentry->d_name.name; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1137 | retval = p9_client_wstat(oldfid, &wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1138 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1139 | clunk_newdir: |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 1140 | if (!retval) |
| 1141 | /* successful rename */ |
| 1142 | d_move(old_dentry, new_dentry); |
| 1143 | up_write(&v9ses->rename_sem); |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1144 | p9_client_clunk(newdirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1145 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1146 | clunk_olddir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1147 | p9_client_clunk(olddirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1148 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1149 | done: |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1150 | return retval; |
| 1151 | } |
| 1152 | |
| 1153 | /** |
Adrian Bunk | 943ffb5 | 2006-01-10 00:10:13 +0100 | [diff] [blame] | 1154 | * v9fs_vfs_getattr - retrieve file metadata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1155 | * @mnt: mount information |
| 1156 | * @dentry: file to get attributes on |
| 1157 | * @stat: metadata structure to populate |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1158 | * |
| 1159 | */ |
| 1160 | |
| 1161 | static int |
| 1162 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1163 | struct kstat *stat) |
| 1164 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1165 | int err; |
| 1166 | struct v9fs_session_info *v9ses; |
| 1167 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1168 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1169 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1170 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 1171 | err = -EPERM; |
| 1172 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 1173 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) |
Eric Van Hensbergen | 9523a84 | 2007-07-13 13:01:27 -0500 | [diff] [blame] | 1174 | return simple_getattr(mnt, dentry, stat); |
| 1175 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1176 | fid = v9fs_fid_lookup(dentry); |
| 1177 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1178 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1179 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1180 | st = p9_client_stat(fid); |
| 1181 | if (IS_ERR(st)) |
| 1182 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1183 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1184 | v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1185 | generic_fillattr(dentry->d_inode, stat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1186 | |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1187 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1188 | kfree(st); |
| 1189 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1192 | static int |
| 1193 | v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry, |
| 1194 | struct kstat *stat) |
| 1195 | { |
| 1196 | int err; |
| 1197 | struct v9fs_session_info *v9ses; |
| 1198 | struct p9_fid *fid; |
| 1199 | struct p9_stat_dotl *st; |
| 1200 | |
| 1201 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 1202 | err = -EPERM; |
| 1203 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1204 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) |
| 1205 | return simple_getattr(mnt, dentry, stat); |
| 1206 | |
| 1207 | fid = v9fs_fid_lookup(dentry); |
| 1208 | if (IS_ERR(fid)) |
| 1209 | return PTR_ERR(fid); |
| 1210 | |
| 1211 | /* Ask for all the fields in stat structure. Server will return |
| 1212 | * whatever it supports |
| 1213 | */ |
| 1214 | |
| 1215 | st = p9_client_getattr_dotl(fid, P9_STATS_ALL); |
| 1216 | if (IS_ERR(st)) |
| 1217 | return PTR_ERR(st); |
| 1218 | |
| 1219 | v9fs_stat2inode_dotl(st, dentry->d_inode); |
| 1220 | generic_fillattr(dentry->d_inode, stat); |
| 1221 | /* Change block size to what the server returned */ |
| 1222 | stat->blksize = st->st_blksize; |
| 1223 | |
| 1224 | kfree(st); |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1228 | /** |
| 1229 | * v9fs_vfs_setattr - set file metadata |
| 1230 | * @dentry: file whose metadata to set |
| 1231 | * @iattr: metadata assignment structure |
| 1232 | * |
| 1233 | */ |
| 1234 | |
| 1235 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 1236 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1237 | int retval; |
| 1238 | struct v9fs_session_info *v9ses; |
| 1239 | struct p9_fid *fid; |
| 1240 | struct p9_wstat wstat; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1241 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1242 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1243 | retval = -EPERM; |
| 1244 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1245 | fid = v9fs_fid_lookup(dentry); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1246 | if(IS_ERR(fid)) |
| 1247 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1248 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1249 | v9fs_blank_wstat(&wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1250 | if (iattr->ia_valid & ATTR_MODE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1251 | wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1252 | |
| 1253 | if (iattr->ia_valid & ATTR_MTIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1254 | wstat.mtime = iattr->ia_mtime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1255 | |
| 1256 | if (iattr->ia_valid & ATTR_ATIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1257 | wstat.atime = iattr->ia_atime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1258 | |
| 1259 | if (iattr->ia_valid & ATTR_SIZE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1260 | wstat.length = iattr->ia_size; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1261 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1262 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1263 | if (iattr->ia_valid & ATTR_UID) |
| 1264 | wstat.n_uid = iattr->ia_uid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1265 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1266 | if (iattr->ia_valid & ATTR_GID) |
| 1267 | wstat.n_gid = iattr->ia_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1270 | retval = p9_client_wstat(fid, &wstat); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 1271 | if (retval < 0) |
| 1272 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1273 | |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 1274 | if ((iattr->ia_valid & ATTR_SIZE) && |
| 1275 | iattr->ia_size != i_size_read(dentry->d_inode)) { |
| 1276 | retval = vmtruncate(dentry->d_inode, iattr->ia_size); |
| 1277 | if (retval) |
| 1278 | return retval; |
| 1279 | } |
| 1280 | |
| 1281 | setattr_copy(dentry->d_inode, iattr); |
| 1282 | mark_inode_dirty(dentry->d_inode); |
| 1283 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /** |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1287 | * v9fs_vfs_setattr_dotl - set file metadata |
| 1288 | * @dentry: file whose metadata to set |
| 1289 | * @iattr: metadata assignment structure |
| 1290 | * |
| 1291 | */ |
| 1292 | |
Aneesh Kumar K.V | 22d8dcd | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1293 | int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1294 | { |
| 1295 | int retval; |
| 1296 | struct v9fs_session_info *v9ses; |
| 1297 | struct p9_fid *fid; |
| 1298 | struct p9_iattr_dotl p9attr; |
| 1299 | |
| 1300 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1301 | |
| 1302 | retval = inode_change_ok(dentry->d_inode, iattr); |
| 1303 | if (retval) |
| 1304 | return retval; |
| 1305 | |
| 1306 | p9attr.valid = iattr->ia_valid; |
| 1307 | p9attr.mode = iattr->ia_mode; |
| 1308 | p9attr.uid = iattr->ia_uid; |
| 1309 | p9attr.gid = iattr->ia_gid; |
| 1310 | p9attr.size = iattr->ia_size; |
| 1311 | p9attr.atime_sec = iattr->ia_atime.tv_sec; |
| 1312 | p9attr.atime_nsec = iattr->ia_atime.tv_nsec; |
| 1313 | p9attr.mtime_sec = iattr->ia_mtime.tv_sec; |
| 1314 | p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; |
| 1315 | |
| 1316 | retval = -EPERM; |
| 1317 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1318 | fid = v9fs_fid_lookup(dentry); |
| 1319 | if (IS_ERR(fid)) |
| 1320 | return PTR_ERR(fid); |
| 1321 | |
| 1322 | retval = p9_client_setattr(fid, &p9attr); |
Stephen Rothwell | 8cef9c6 | 2010-06-22 11:15:01 +1000 | [diff] [blame] | 1323 | if (retval < 0) |
| 1324 | return retval; |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1325 | |
Stephen Rothwell | 8cef9c6 | 2010-06-22 11:15:01 +1000 | [diff] [blame] | 1326 | if ((iattr->ia_valid & ATTR_SIZE) && |
| 1327 | iattr->ia_size != i_size_read(dentry->d_inode)) { |
| 1328 | retval = vmtruncate(dentry->d_inode, iattr->ia_size); |
| 1329 | if (retval) |
| 1330 | return retval; |
| 1331 | } |
| 1332 | |
| 1333 | setattr_copy(dentry->d_inode, iattr); |
| 1334 | mark_inode_dirty(dentry->d_inode); |
Aneesh Kumar K.V | 6e8dc55 | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1335 | if (iattr->ia_valid & ATTR_MODE) { |
| 1336 | /* We also want to update ACL when we update mode bits */ |
| 1337 | retval = v9fs_acl_chmod(dentry); |
| 1338 | if (retval < 0) |
| 1339 | return retval; |
| 1340 | } |
Stephen Rothwell | 8cef9c6 | 2010-06-22 11:15:01 +1000 | [diff] [blame] | 1341 | return 0; |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1345 | * v9fs_stat2inode - populate an inode structure with mistat info |
| 1346 | * @stat: Plan 9 metadata (mistat) structure |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1347 | * @inode: inode to populate |
| 1348 | * @sb: superblock of filesystem |
| 1349 | * |
| 1350 | */ |
| 1351 | |
| 1352 | void |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1353 | v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1354 | struct super_block *sb) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1355 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1356 | char ext[32]; |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1357 | char tag_name[14]; |
| 1358 | unsigned int i_nlink; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1359 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
| 1360 | |
| 1361 | inode->i_nlink = 1; |
| 1362 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1363 | inode->i_atime.tv_sec = stat->atime; |
| 1364 | inode->i_mtime.tv_sec = stat->mtime; |
| 1365 | inode->i_ctime.tv_sec = stat->mtime; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1366 | |
Latchesar Ionkov | bd32b82 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1367 | inode->i_uid = v9ses->dfltuid; |
| 1368 | inode->i_gid = v9ses->dfltgid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1369 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1370 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1371 | inode->i_uid = stat->n_uid; |
| 1372 | inode->i_gid = stat->n_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1373 | } |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1374 | if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) { |
| 1375 | if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) { |
| 1376 | /* |
| 1377 | * Hadlink support got added later to |
| 1378 | * to the .u extension. So there can be |
| 1379 | * server out there that doesn't support |
| 1380 | * this even with .u extension. So check |
| 1381 | * for non NULL stat->extension |
| 1382 | */ |
| 1383 | strncpy(ext, stat->extension, sizeof(ext)); |
| 1384 | /* HARDLINKCOUNT %u */ |
| 1385 | sscanf(ext, "%13s %u", tag_name, &i_nlink); |
| 1386 | if (!strncmp(tag_name, "HARDLINKCOUNT", 13)) |
| 1387 | inode->i_nlink = i_nlink; |
| 1388 | } |
| 1389 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1390 | inode->i_mode = p9mode2unixmode(v9ses, stat->mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1391 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { |
| 1392 | char type = 0; |
| 1393 | int major = -1; |
| 1394 | int minor = -1; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1395 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1396 | strncpy(ext, stat->extension, sizeof(ext)); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1397 | sscanf(ext, "%c %u %u", &type, &major, &minor); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1398 | switch (type) { |
| 1399 | case 'c': |
| 1400 | inode->i_mode &= ~S_IFBLK; |
| 1401 | inode->i_mode |= S_IFCHR; |
| 1402 | break; |
| 1403 | case 'b': |
| 1404 | break; |
| 1405 | default: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1406 | P9_DPRINTK(P9_DEBUG_ERROR, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1407 | "Unknown special type %c %s\n", type, |
| 1408 | stat->extension); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1409 | }; |
| 1410 | inode->i_rdev = MKDEV(major, minor); |
Magnus Deininger | 57c7b4e | 2008-10-17 12:44:46 -0500 | [diff] [blame] | 1411 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1412 | } else |
| 1413 | inode->i_rdev = 0; |
| 1414 | |
Abhishek Kulkarni | 7549ae3 | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1415 | i_size_write(inode, stat->length); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1416 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1417 | /* not real number of blocks, but 512 byte ones ... */ |
Abhishek Kulkarni | 7549ae3 | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1418 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | /** |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1422 | * v9fs_stat2inode_dotl - populate an inode structure with stat info |
| 1423 | * @stat: stat structure |
| 1424 | * @inode: inode to populate |
| 1425 | * @sb: superblock of filesystem |
| 1426 | * |
| 1427 | */ |
| 1428 | |
| 1429 | void |
| 1430 | v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) |
| 1431 | { |
| 1432 | |
| 1433 | if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { |
| 1434 | inode->i_atime.tv_sec = stat->st_atime_sec; |
| 1435 | inode->i_atime.tv_nsec = stat->st_atime_nsec; |
| 1436 | inode->i_mtime.tv_sec = stat->st_mtime_sec; |
| 1437 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; |
| 1438 | inode->i_ctime.tv_sec = stat->st_ctime_sec; |
| 1439 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; |
| 1440 | inode->i_uid = stat->st_uid; |
| 1441 | inode->i_gid = stat->st_gid; |
| 1442 | inode->i_nlink = stat->st_nlink; |
| 1443 | inode->i_mode = stat->st_mode; |
| 1444 | inode->i_rdev = new_decode_dev(stat->st_rdev); |
| 1445 | |
| 1446 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) |
| 1447 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 1448 | |
| 1449 | i_size_write(inode, stat->st_size); |
| 1450 | inode->i_blocks = stat->st_blocks; |
| 1451 | } else { |
| 1452 | if (stat->st_result_mask & P9_STATS_ATIME) { |
| 1453 | inode->i_atime.tv_sec = stat->st_atime_sec; |
| 1454 | inode->i_atime.tv_nsec = stat->st_atime_nsec; |
| 1455 | } |
| 1456 | if (stat->st_result_mask & P9_STATS_MTIME) { |
| 1457 | inode->i_mtime.tv_sec = stat->st_mtime_sec; |
| 1458 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; |
| 1459 | } |
| 1460 | if (stat->st_result_mask & P9_STATS_CTIME) { |
| 1461 | inode->i_ctime.tv_sec = stat->st_ctime_sec; |
| 1462 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; |
| 1463 | } |
| 1464 | if (stat->st_result_mask & P9_STATS_UID) |
| 1465 | inode->i_uid = stat->st_uid; |
| 1466 | if (stat->st_result_mask & P9_STATS_GID) |
| 1467 | inode->i_gid = stat->st_gid; |
| 1468 | if (stat->st_result_mask & P9_STATS_NLINK) |
| 1469 | inode->i_nlink = stat->st_nlink; |
| 1470 | if (stat->st_result_mask & P9_STATS_MODE) { |
| 1471 | inode->i_mode = stat->st_mode; |
| 1472 | if ((S_ISBLK(inode->i_mode)) || |
| 1473 | (S_ISCHR(inode->i_mode))) |
| 1474 | init_special_inode(inode, inode->i_mode, |
| 1475 | inode->i_rdev); |
| 1476 | } |
| 1477 | if (stat->st_result_mask & P9_STATS_RDEV) |
| 1478 | inode->i_rdev = new_decode_dev(stat->st_rdev); |
| 1479 | if (stat->st_result_mask & P9_STATS_SIZE) |
| 1480 | i_size_write(inode, stat->st_size); |
| 1481 | if (stat->st_result_mask & P9_STATS_BLOCKS) |
| 1482 | inode->i_blocks = stat->st_blocks; |
| 1483 | } |
| 1484 | if (stat->st_result_mask & P9_STATS_GEN) |
| 1485 | inode->i_generation = stat->st_gen; |
| 1486 | |
| 1487 | /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION |
| 1488 | * because the inode structure does not have fields for them. |
| 1489 | */ |
| 1490 | } |
| 1491 | |
| 1492 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1493 | * v9fs_qid2ino - convert qid into inode number |
| 1494 | * @qid: qid to hash |
| 1495 | * |
| 1496 | * BUG: potential for inode number collisions? |
| 1497 | */ |
| 1498 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1499 | ino_t v9fs_qid2ino(struct p9_qid *qid) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1500 | { |
| 1501 | u64 path = qid->path + 2; |
| 1502 | ino_t i = 0; |
| 1503 | |
| 1504 | if (sizeof(ino_t) == sizeof(path)) |
| 1505 | memcpy(&i, &path, sizeof(ino_t)); |
| 1506 | else |
| 1507 | i = (ino_t) (path ^ (path >> 32)); |
| 1508 | |
| 1509 | return i; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1513 | * v9fs_readlink - read a symlink's location (internal version) |
| 1514 | * @dentry: dentry for symlink |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1515 | * @buffer: buffer to load symlink location into |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1516 | * @buflen: length of buffer |
| 1517 | * |
| 1518 | */ |
| 1519 | |
| 1520 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 1521 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1522 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1523 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1524 | struct v9fs_session_info *v9ses; |
| 1525 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1526 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1527 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1528 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); |
| 1529 | retval = -EPERM; |
| 1530 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1531 | fid = v9fs_fid_lookup(dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1532 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1533 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1534 | |
M. Mohan Kumar | 329176c | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 1535 | if (!v9fs_proto_dotu(v9ses)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1536 | return -EBADF; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1537 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1538 | st = p9_client_stat(fid); |
| 1539 | if (IS_ERR(st)) |
| 1540 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1541 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1542 | if (!(st->mode & P9_DMSYMLINK)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1543 | retval = -EINVAL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1544 | goto done; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | /* copy extension buffer into buffer */ |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1548 | strncpy(buffer, st->extension, buflen); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1549 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1550 | P9_DPRINTK(P9_DEBUG_VFS, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1551 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1552 | |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1553 | retval = strnlen(buffer, buflen); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1554 | done: |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1555 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1556 | kfree(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1557 | return retval; |
| 1558 | } |
| 1559 | |
| 1560 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1561 | * v9fs_vfs_follow_link - follow a symlink path |
| 1562 | * @dentry: dentry for symlink |
| 1563 | * @nd: nameidata |
| 1564 | * |
| 1565 | */ |
| 1566 | |
| 1567 | static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 1568 | { |
| 1569 | int len = 0; |
| 1570 | char *link = __getname(); |
| 1571 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1572 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1573 | |
| 1574 | if (!link) |
| 1575 | link = ERR_PTR(-ENOMEM); |
| 1576 | else { |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1577 | len = v9fs_readlink(dentry, link, PATH_MAX); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1578 | |
| 1579 | if (len < 0) { |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1580 | __putname(link); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1581 | link = ERR_PTR(len); |
| 1582 | } else |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1583 | link[min(len, PATH_MAX-1)] = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1584 | } |
| 1585 | nd_set_link(nd, link); |
| 1586 | |
| 1587 | return NULL; |
| 1588 | } |
| 1589 | |
| 1590 | /** |
| 1591 | * v9fs_vfs_put_link - release a symlink path |
| 1592 | * @dentry: dentry for symlink |
| 1593 | * @nd: nameidata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1594 | * @p: unused |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1595 | * |
| 1596 | */ |
| 1597 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1598 | static void |
| 1599 | v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1600 | { |
| 1601 | char *s = nd_get_link(nd); |
| 1602 | |
Duane Griffin | 6ff2320 | 2008-12-19 16:45:21 -0600 | [diff] [blame] | 1603 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, |
| 1604 | IS_ERR(s) ? "<error>" : s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1605 | if (!IS_ERR(s)) |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1606 | __putname(s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1609 | /** |
| 1610 | * v9fs_vfs_mkspecial - create a special file |
| 1611 | * @dir: inode to create special file in |
| 1612 | * @dentry: dentry to create |
| 1613 | * @mode: mode to create special file |
| 1614 | * @extension: 9p2000.u format extension string representing special file |
| 1615 | * |
| 1616 | */ |
| 1617 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1618 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
| 1619 | int mode, const char *extension) |
| 1620 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1621 | u32 perm; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1622 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1623 | struct p9_fid *fid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1624 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1625 | v9ses = v9fs_inode2v9ses(dir); |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1626 | if (!v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1627 | P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1628 | return -EPERM; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1629 | } |
| 1630 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1631 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1632 | fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm, |
| 1633 | P9_OREAD); |
| 1634 | if (IS_ERR(fid)) |
| 1635 | return PTR_ERR(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1636 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1637 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1638 | return 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | /** |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1642 | * v9fs_vfs_symlink_dotl - helper function to create symlinks |
| 1643 | * @dir: directory inode containing symlink |
| 1644 | * @dentry: dentry for symlink |
| 1645 | * @symname: symlink data |
| 1646 | * |
| 1647 | * See Also: 9P2000.L RFC for more information |
| 1648 | * |
| 1649 | */ |
| 1650 | |
| 1651 | static int |
| 1652 | v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, |
| 1653 | const char *symname) |
| 1654 | { |
| 1655 | struct v9fs_session_info *v9ses; |
| 1656 | struct p9_fid *dfid; |
| 1657 | struct p9_fid *fid = NULL; |
| 1658 | struct inode *inode; |
| 1659 | struct p9_qid qid; |
| 1660 | char *name; |
| 1661 | int err; |
| 1662 | gid_t gid; |
| 1663 | |
| 1664 | name = (char *) dentry->d_name.name; |
| 1665 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n", |
| 1666 | dir->i_ino, name, symname); |
| 1667 | v9ses = v9fs_inode2v9ses(dir); |
| 1668 | |
| 1669 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 1670 | if (IS_ERR(dfid)) { |
| 1671 | err = PTR_ERR(dfid); |
| 1672 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 1673 | return err; |
| 1674 | } |
| 1675 | |
| 1676 | gid = v9fs_get_fsgid_for_create(dir); |
| 1677 | |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1678 | /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */ |
| 1679 | err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid); |
| 1680 | |
| 1681 | if (err < 0) { |
| 1682 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); |
| 1683 | goto error; |
| 1684 | } |
| 1685 | |
| 1686 | if (v9ses->cache) { |
| 1687 | /* Now walk from the parent so we can get an unopened fid. */ |
| 1688 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 1689 | if (IS_ERR(fid)) { |
| 1690 | err = PTR_ERR(fid); |
| 1691 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 1692 | err); |
| 1693 | fid = NULL; |
| 1694 | goto error; |
| 1695 | } |
| 1696 | |
| 1697 | /* instantiate inode and assign the unopened fid to dentry */ |
| 1698 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 1699 | if (IS_ERR(inode)) { |
| 1700 | err = PTR_ERR(inode); |
| 1701 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 1702 | err); |
| 1703 | goto error; |
| 1704 | } |
| 1705 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 1706 | d_instantiate(dentry, inode); |
| 1707 | err = v9fs_fid_add(dentry, fid); |
| 1708 | if (err < 0) |
| 1709 | goto error; |
| 1710 | fid = NULL; |
| 1711 | } else { |
| 1712 | /* Not in cached mode. No need to populate inode with stat */ |
| 1713 | inode = v9fs_get_inode(dir->i_sb, S_IFLNK); |
| 1714 | if (IS_ERR(inode)) { |
| 1715 | err = PTR_ERR(inode); |
| 1716 | goto error; |
| 1717 | } |
| 1718 | dentry->d_op = &v9fs_dentry_operations; |
| 1719 | d_instantiate(dentry, inode); |
| 1720 | } |
| 1721 | |
| 1722 | error: |
| 1723 | if (fid) |
| 1724 | p9_client_clunk(fid); |
| 1725 | |
| 1726 | return err; |
| 1727 | } |
| 1728 | |
| 1729 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1730 | * v9fs_vfs_symlink - helper function to create symlinks |
| 1731 | * @dir: directory inode containing symlink |
| 1732 | * @dentry: dentry for symlink |
| 1733 | * @symname: symlink data |
| 1734 | * |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1735 | * See Also: 9P2000.u RFC for more information |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1736 | * |
| 1737 | */ |
| 1738 | |
| 1739 | static int |
| 1740 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) |
| 1741 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1742 | P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, |
| 1743 | dentry->d_name.name, symname); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1744 | |
| 1745 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); |
| 1746 | } |
| 1747 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1748 | /** |
| 1749 | * v9fs_vfs_link - create a hardlink |
| 1750 | * @old_dentry: dentry for file to link to |
| 1751 | * @dir: inode destination for new link |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1752 | * @dentry: dentry for link |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1753 | * |
| 1754 | */ |
| 1755 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1756 | static int |
| 1757 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1758 | struct dentry *dentry) |
| 1759 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1760 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1761 | struct p9_fid *oldfid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1762 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1763 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1764 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1765 | " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1766 | old_dentry->d_name.name); |
| 1767 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1768 | oldfid = v9fs_fid_clone(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1769 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1770 | return PTR_ERR(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1771 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1772 | name = __getname(); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1773 | if (unlikely(!name)) { |
| 1774 | retval = -ENOMEM; |
| 1775 | goto clunk_fid; |
| 1776 | } |
Florin Malita | 0710d36 | 2006-06-25 05:48:31 -0700 | [diff] [blame] | 1777 | |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1778 | sprintf(name, "%d\n", oldfid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1779 | retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1780 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1781 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1782 | clunk_fid: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1783 | p9_client_clunk(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1784 | return retval; |
| 1785 | } |
| 1786 | |
| 1787 | /** |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 1788 | * v9fs_vfs_link_dotl - create a hardlink for dotl |
| 1789 | * @old_dentry: dentry for file to link to |
| 1790 | * @dir: inode destination for new link |
| 1791 | * @dentry: dentry for link |
| 1792 | * |
| 1793 | */ |
| 1794 | |
| 1795 | static int |
| 1796 | v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir, |
| 1797 | struct dentry *dentry) |
| 1798 | { |
| 1799 | int err; |
| 1800 | struct p9_fid *dfid, *oldfid; |
| 1801 | char *name; |
| 1802 | struct v9fs_session_info *v9ses; |
| 1803 | struct dentry *dir_dentry; |
| 1804 | |
| 1805 | P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n", |
| 1806 | dir->i_ino, old_dentry->d_name.name, |
| 1807 | dentry->d_name.name); |
| 1808 | |
| 1809 | v9ses = v9fs_inode2v9ses(dir); |
| 1810 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
| 1811 | dfid = v9fs_fid_lookup(dir_dentry); |
| 1812 | if (IS_ERR(dfid)) |
| 1813 | return PTR_ERR(dfid); |
| 1814 | |
| 1815 | oldfid = v9fs_fid_lookup(old_dentry); |
| 1816 | if (IS_ERR(oldfid)) |
| 1817 | return PTR_ERR(oldfid); |
| 1818 | |
| 1819 | name = (char *) dentry->d_name.name; |
| 1820 | |
| 1821 | err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name); |
| 1822 | |
| 1823 | if (err < 0) { |
| 1824 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); |
| 1825 | return err; |
| 1826 | } |
| 1827 | |
| 1828 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 1829 | /* Get the latest stat info from server. */ |
| 1830 | struct p9_fid *fid; |
| 1831 | struct p9_stat_dotl *st; |
| 1832 | |
| 1833 | fid = v9fs_fid_lookup(old_dentry); |
| 1834 | if (IS_ERR(fid)) |
| 1835 | return PTR_ERR(fid); |
| 1836 | |
| 1837 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); |
| 1838 | if (IS_ERR(st)) |
| 1839 | return PTR_ERR(st); |
| 1840 | |
| 1841 | v9fs_stat2inode_dotl(st, old_dentry->d_inode); |
| 1842 | |
| 1843 | kfree(st); |
| 1844 | } else { |
| 1845 | /* Caching disabled. No need to get upto date stat info. |
Al Viro | 7de9c6e | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 1846 | * This dentry will be released immediately. So, just hold the |
| 1847 | * inode |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 1848 | */ |
Al Viro | 7de9c6e | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 1849 | ihold(old_dentry->d_inode); |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | dentry->d_op = old_dentry->d_op; |
| 1853 | d_instantiate(dentry, old_dentry->d_inode); |
| 1854 | |
| 1855 | return err; |
| 1856 | } |
| 1857 | |
| 1858 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1859 | * v9fs_vfs_mknod - create a special file |
| 1860 | * @dir: inode destination for new link |
| 1861 | * @dentry: dentry for file |
| 1862 | * @mode: mode for creation |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1863 | * @rdev: device associated with special file |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1864 | * |
| 1865 | */ |
| 1866 | |
| 1867 | static int |
| 1868 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) |
| 1869 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1870 | int retval; |
| 1871 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1872 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1873 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1874 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1875 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1876 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1877 | if (!new_valid_dev(rdev)) |
| 1878 | return -EINVAL; |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1879 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1880 | name = __getname(); |
Eugene Teo | c0291a0 | 2006-03-25 03:07:27 -0800 | [diff] [blame] | 1881 | if (!name) |
| 1882 | return -ENOMEM; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1883 | /* build extension */ |
| 1884 | if (S_ISBLK(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1885 | sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1886 | else if (S_ISCHR(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1887 | sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1888 | else if (S_ISFIFO(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1889 | *name = 0; |
Venkateswararao Jujjuri | 75cc5c9 | 2010-05-22 12:20:30 -0500 | [diff] [blame] | 1890 | else if (S_ISSOCK(mode)) |
| 1891 | *name = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1892 | else { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1893 | __putname(name); |
| 1894 | return -EINVAL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1897 | retval = v9fs_vfs_mkspecial(dir, dentry, mode, name); |
| 1898 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1899 | |
| 1900 | return retval; |
| 1901 | } |
| 1902 | |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1903 | /** |
| 1904 | * v9fs_vfs_mknod_dotl - create a special file |
| 1905 | * @dir: inode destination for new link |
| 1906 | * @dentry: dentry for file |
| 1907 | * @mode: mode for creation |
| 1908 | * @rdev: device associated with special file |
| 1909 | * |
| 1910 | */ |
| 1911 | static int |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1912 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int omode, |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1913 | dev_t rdev) |
| 1914 | { |
| 1915 | int err; |
| 1916 | char *name; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1917 | mode_t mode; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1918 | struct v9fs_session_info *v9ses; |
| 1919 | struct p9_fid *fid = NULL, *dfid = NULL; |
| 1920 | struct inode *inode; |
| 1921 | gid_t gid; |
| 1922 | struct p9_qid qid; |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 1923 | struct dentry *dir_dentry; |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1924 | struct posix_acl *dacl = NULL, *pacl = NULL; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1925 | |
| 1926 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1927 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1928 | dentry->d_name.name, omode, MAJOR(rdev), MINOR(rdev)); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1929 | |
| 1930 | if (!new_valid_dev(rdev)) |
| 1931 | return -EINVAL; |
| 1932 | |
| 1933 | v9ses = v9fs_inode2v9ses(dir); |
| 1934 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 1935 | dfid = v9fs_fid_lookup(dir_dentry); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1936 | if (IS_ERR(dfid)) { |
| 1937 | err = PTR_ERR(dfid); |
| 1938 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 1939 | dfid = NULL; |
| 1940 | goto error; |
| 1941 | } |
| 1942 | |
| 1943 | gid = v9fs_get_fsgid_for_create(dir); |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1944 | mode = omode; |
| 1945 | /* Update mode based on ACL value */ |
| 1946 | err = v9fs_acl_mode(dir, &mode, &dacl, &pacl); |
| 1947 | if (err) { |
| 1948 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1949 | "Failed to get acl values in mknod %d\n", err); |
| 1950 | goto error; |
| 1951 | } |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1952 | name = (char *) dentry->d_name.name; |
| 1953 | |
| 1954 | err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); |
| 1955 | if (err < 0) |
| 1956 | goto error; |
| 1957 | |
| 1958 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 1959 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 1960 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 1961 | if (IS_ERR(fid)) { |
| 1962 | err = PTR_ERR(fid); |
| 1963 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 1964 | err); |
| 1965 | fid = NULL; |
| 1966 | goto error; |
| 1967 | } |
| 1968 | |
| 1969 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 1970 | if (IS_ERR(inode)) { |
| 1971 | err = PTR_ERR(inode); |
| 1972 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 1973 | err); |
| 1974 | goto error; |
| 1975 | } |
| 1976 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 1977 | d_instantiate(dentry, inode); |
| 1978 | err = v9fs_fid_add(dentry, fid); |
| 1979 | if (err < 0) |
| 1980 | goto error; |
| 1981 | fid = NULL; |
| 1982 | } else { |
| 1983 | /* |
| 1984 | * Not in cached mode. No need to populate inode with stat. |
| 1985 | * socket syscall returns a fd, so we need instantiate |
| 1986 | */ |
| 1987 | inode = v9fs_get_inode(dir->i_sb, mode); |
| 1988 | if (IS_ERR(inode)) { |
| 1989 | err = PTR_ERR(inode); |
| 1990 | goto error; |
| 1991 | } |
| 1992 | dentry->d_op = &v9fs_dentry_operations; |
| 1993 | d_instantiate(dentry, inode); |
| 1994 | } |
Aneesh Kumar K.V | ad77dbc | 2010-09-28 00:27:40 +0530 | [diff] [blame] | 1995 | /* Now set the ACL based on the default value */ |
| 1996 | v9fs_set_create_acl(dentry, dacl, pacl); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1997 | error: |
| 1998 | if (fid) |
| 1999 | p9_client_clunk(fid); |
| 2000 | return err; |
| 2001 | } |
| 2002 | |
M. Mohan Kumar | 329176c | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2003 | static int |
| 2004 | v9fs_vfs_readlink_dotl(struct dentry *dentry, char *buffer, int buflen) |
| 2005 | { |
| 2006 | int retval; |
| 2007 | struct p9_fid *fid; |
| 2008 | char *target = NULL; |
| 2009 | |
| 2010 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); |
| 2011 | retval = -EPERM; |
| 2012 | fid = v9fs_fid_lookup(dentry); |
| 2013 | if (IS_ERR(fid)) |
| 2014 | return PTR_ERR(fid); |
| 2015 | |
| 2016 | retval = p9_client_readlink(fid, &target); |
| 2017 | if (retval < 0) |
| 2018 | return retval; |
| 2019 | |
| 2020 | strncpy(buffer, target, buflen); |
| 2021 | P9_DPRINTK(P9_DEBUG_VFS, "%s -> %s\n", dentry->d_name.name, buffer); |
| 2022 | |
| 2023 | retval = strnlen(buffer, buflen); |
| 2024 | return retval; |
| 2025 | } |
| 2026 | |
| 2027 | /** |
| 2028 | * v9fs_vfs_follow_link_dotl - follow a symlink path |
| 2029 | * @dentry: dentry for symlink |
| 2030 | * @nd: nameidata |
| 2031 | * |
| 2032 | */ |
| 2033 | |
| 2034 | static void * |
| 2035 | v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) |
| 2036 | { |
| 2037 | int len = 0; |
| 2038 | char *link = __getname(); |
| 2039 | |
| 2040 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
| 2041 | |
| 2042 | if (!link) |
| 2043 | link = ERR_PTR(-ENOMEM); |
| 2044 | else { |
| 2045 | len = v9fs_vfs_readlink_dotl(dentry, link, PATH_MAX); |
| 2046 | if (len < 0) { |
| 2047 | __putname(link); |
| 2048 | link = ERR_PTR(len); |
| 2049 | } else |
| 2050 | link[min(len, PATH_MAX-1)] = 0; |
| 2051 | } |
| 2052 | nd_set_link(nd, link); |
| 2053 | |
| 2054 | return NULL; |
| 2055 | } |
| 2056 | |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2057 | static const struct inode_operations v9fs_dir_inode_operations_dotu = { |
| 2058 | .create = v9fs_vfs_create, |
| 2059 | .lookup = v9fs_vfs_lookup, |
| 2060 | .symlink = v9fs_vfs_symlink, |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 2061 | .link = v9fs_vfs_link, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2062 | .unlink = v9fs_vfs_unlink, |
| 2063 | .mkdir = v9fs_vfs_mkdir, |
| 2064 | .rmdir = v9fs_vfs_rmdir, |
Aneesh Kumar K.V | 1d76e31 | 2010-08-30 17:43:07 +0000 | [diff] [blame] | 2065 | .mknod = v9fs_vfs_mknod, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2066 | .rename = v9fs_vfs_rename, |
| 2067 | .getattr = v9fs_vfs_getattr, |
| 2068 | .setattr = v9fs_vfs_setattr, |
| 2069 | }; |
| 2070 | |
| 2071 | static const struct inode_operations v9fs_dir_inode_operations_dotl = { |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 2072 | .create = v9fs_vfs_create_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2073 | .lookup = v9fs_vfs_lookup, |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 2074 | .link = v9fs_vfs_link_dotl, |
| 2075 | .symlink = v9fs_vfs_symlink_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2076 | .unlink = v9fs_vfs_unlink, |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 2077 | .mkdir = v9fs_vfs_mkdir_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2078 | .rmdir = v9fs_vfs_rmdir, |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 2079 | .mknod = v9fs_vfs_mknod_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2080 | .rename = v9fs_vfs_rename, |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 2081 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 2082 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame] | 2083 | .setxattr = generic_setxattr, |
| 2084 | .getxattr = generic_getxattr, |
| 2085 | .removexattr = generic_removexattr, |
| 2086 | .listxattr = v9fs_listxattr, |
Aneesh Kumar K.V | 85ff872 | 2010-09-28 00:27:39 +0530 | [diff] [blame] | 2087 | .check_acl = v9fs_check_acl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2088 | }; |
| 2089 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 2090 | static const struct inode_operations v9fs_dir_inode_operations = { |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 2091 | .create = v9fs_vfs_create, |
| 2092 | .lookup = v9fs_vfs_lookup, |
| 2093 | .unlink = v9fs_vfs_unlink, |
| 2094 | .mkdir = v9fs_vfs_mkdir, |
| 2095 | .rmdir = v9fs_vfs_rmdir, |
| 2096 | .mknod = v9fs_vfs_mknod, |
| 2097 | .rename = v9fs_vfs_rename, |
| 2098 | .getattr = v9fs_vfs_getattr, |
| 2099 | .setattr = v9fs_vfs_setattr, |
| 2100 | }; |
| 2101 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 2102 | static const struct inode_operations v9fs_file_inode_operations = { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2103 | .getattr = v9fs_vfs_getattr, |
| 2104 | .setattr = v9fs_vfs_setattr, |
| 2105 | }; |
| 2106 | |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2107 | static const struct inode_operations v9fs_file_inode_operations_dotl = { |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 2108 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 2109 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame] | 2110 | .setxattr = generic_setxattr, |
| 2111 | .getxattr = generic_getxattr, |
| 2112 | .removexattr = generic_removexattr, |
| 2113 | .listxattr = v9fs_listxattr, |
Aneesh Kumar K.V | 85ff872 | 2010-09-28 00:27:39 +0530 | [diff] [blame] | 2114 | .check_acl = v9fs_check_acl, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2115 | }; |
| 2116 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 2117 | static const struct inode_operations v9fs_symlink_inode_operations = { |
Al Viro | 204f2f0 | 2009-12-23 00:35:54 -0500 | [diff] [blame] | 2118 | .readlink = generic_readlink, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 2119 | .follow_link = v9fs_vfs_follow_link, |
| 2120 | .put_link = v9fs_vfs_put_link, |
| 2121 | .getattr = v9fs_vfs_getattr, |
| 2122 | .setattr = v9fs_vfs_setattr, |
| 2123 | }; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2124 | |
| 2125 | static const struct inode_operations v9fs_symlink_inode_operations_dotl = { |
M. Mohan Kumar | 329176c | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 2126 | .readlink = v9fs_vfs_readlink_dotl, |
| 2127 | .follow_link = v9fs_vfs_follow_link_dotl, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2128 | .put_link = v9fs_vfs_put_link, |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 2129 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 2130 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame] | 2131 | .setxattr = generic_setxattr, |
| 2132 | .getxattr = generic_getxattr, |
| 2133 | .removexattr = generic_removexattr, |
| 2134 | .listxattr = v9fs_listxattr, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 2135 | }; |