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; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 52 | static const struct inode_operations v9fs_file_inode_operations; |
| 53 | static const struct inode_operations v9fs_symlink_inode_operations; |
Aneesh Kumar K.V | f5fc614 | 2010-10-12 13:02:25 +0530 | [diff] [blame] | 54 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 55 | /** |
| 56 | * unixmode2p9mode - convert unix mode bits to plan 9 |
| 57 | * @v9ses: v9fs session information |
| 58 | * @mode: mode to convert |
| 59 | * |
| 60 | */ |
| 61 | |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 62 | static u32 unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 63 | { |
| 64 | int res; |
| 65 | res = mode & 0777; |
| 66 | if (S_ISDIR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 67 | res |= P9_DMDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 68 | if (v9fs_proto_dotu(v9ses)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 69 | if (v9ses->nodev == 0) { |
| 70 | if (S_ISSOCK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 71 | res |= P9_DMSOCKET; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 72 | if (S_ISFIFO(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 73 | res |= P9_DMNAMEDPIPE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 74 | if (S_ISBLK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 75 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 76 | if (S_ISCHR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 77 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | if ((mode & S_ISUID) == S_ISUID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 81 | res |= P9_DMSETUID; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 82 | if ((mode & S_ISGID) == S_ISGID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 83 | res |= P9_DMSETGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 84 | if ((mode & S_ISVTX) == S_ISVTX) |
| 85 | res |= P9_DMSETVTX; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 86 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 87 | return res; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * p9mode2unixmode- convert plan9 mode bits to unix mode bits |
| 92 | * @v9ses: v9fs session information |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 93 | * @stat: p9_wstat from which mode need to be derived |
| 94 | * @rdev: major number, minor number in case of device files. |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 95 | * |
| 96 | */ |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 97 | static int p9mode2unixmode(struct v9fs_session_info *v9ses, |
| 98 | struct p9_wstat *stat, dev_t *rdev) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 99 | { |
| 100 | int res; |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 101 | int mode = stat->mode; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 102 | |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 103 | res = mode & S_IALLUGO; |
| 104 | *rdev = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 105 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 106 | if ((mode & P9_DMDIR) == P9_DMDIR) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 107 | res |= S_IFDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 108 | else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses))) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 109 | res |= S_IFLNK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 110 | else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 111 | && (v9ses->nodev == 0)) |
| 112 | res |= S_IFSOCK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 113 | else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 114 | && (v9ses->nodev == 0)) |
| 115 | res |= S_IFIFO; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 116 | else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 117 | && (v9ses->nodev == 0)) { |
| 118 | char type = 0, ext[32]; |
| 119 | int major = -1, minor = -1; |
| 120 | |
| 121 | strncpy(ext, stat->extension, sizeof(ext)); |
| 122 | sscanf(ext, "%c %u %u", &type, &major, &minor); |
| 123 | switch (type) { |
| 124 | case 'c': |
| 125 | res |= S_IFCHR; |
| 126 | break; |
| 127 | case 'b': |
| 128 | res |= S_IFBLK; |
| 129 | break; |
| 130 | default: |
| 131 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 132 | "Unknown special type %c %s\n", type, |
| 133 | stat->extension); |
| 134 | }; |
| 135 | *rdev = MKDEV(major, minor); |
| 136 | } else |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 137 | res |= S_IFREG; |
| 138 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 139 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 140 | if ((mode & P9_DMSETUID) == P9_DMSETUID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 141 | res |= S_ISUID; |
| 142 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 143 | if ((mode & P9_DMSETGID) == P9_DMSETGID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 144 | res |= S_ISGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 145 | |
| 146 | if ((mode & P9_DMSETVTX) == P9_DMSETVTX) |
| 147 | res |= S_ISVTX; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 148 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 149 | return res; |
| 150 | } |
| 151 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 152 | /** |
| 153 | * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits |
| 154 | * @uflags: flags to convert |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 155 | * @extended: if .u extensions are active |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 156 | */ |
| 157 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 158 | int v9fs_uflags2omode(int uflags, int extended) |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 159 | { |
| 160 | int ret; |
| 161 | |
| 162 | ret = 0; |
| 163 | switch (uflags&3) { |
| 164 | default: |
| 165 | case O_RDONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 166 | ret = P9_OREAD; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 167 | break; |
| 168 | |
| 169 | case O_WRONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 170 | ret = P9_OWRITE; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 171 | break; |
| 172 | |
| 173 | case O_RDWR: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 174 | ret = P9_ORDWR; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 175 | break; |
| 176 | } |
| 177 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 178 | if (uflags & O_TRUNC) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 179 | ret |= P9_OTRUNC; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 180 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 181 | if (extended) { |
| 182 | if (uflags & O_EXCL) |
| 183 | ret |= P9_OEXCL; |
| 184 | |
| 185 | if (uflags & O_APPEND) |
| 186 | ret |= P9_OAPPEND; |
| 187 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 192 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 193 | * v9fs_blank_wstat - helper function to setup a 9P stat structure |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 194 | * @wstat: structure to initialize |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 195 | * |
| 196 | */ |
| 197 | |
M. Mohan Kumar | 7a4439c | 2010-02-08 15:36:48 -0600 | [diff] [blame] | 198 | void |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 199 | v9fs_blank_wstat(struct p9_wstat *wstat) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 200 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 201 | wstat->type = ~0; |
| 202 | wstat->dev = ~0; |
| 203 | wstat->qid.type = ~0; |
| 204 | wstat->qid.version = ~0; |
| 205 | *((long long *)&wstat->qid.path) = ~0; |
| 206 | wstat->mode = ~0; |
| 207 | wstat->atime = ~0; |
| 208 | wstat->mtime = ~0; |
| 209 | wstat->length = ~0; |
| 210 | wstat->name = NULL; |
| 211 | wstat->uid = NULL; |
| 212 | wstat->gid = NULL; |
| 213 | wstat->muid = NULL; |
| 214 | wstat->n_uid = ~0; |
| 215 | wstat->n_gid = ~0; |
| 216 | wstat->n_muid = ~0; |
| 217 | wstat->extension = NULL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 220 | /** |
| 221 | * v9fs_alloc_inode - helper function to allocate an inode |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 222 | * |
| 223 | */ |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 224 | struct inode *v9fs_alloc_inode(struct super_block *sb) |
| 225 | { |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 226 | struct v9fs_inode *v9inode; |
| 227 | v9inode = (struct v9fs_inode *)kmem_cache_alloc(v9fs_inode_cache, |
| 228 | GFP_KERNEL); |
| 229 | if (!v9inode) |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 230 | return NULL; |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 231 | #ifdef CONFIG_9P_FSCACHE |
| 232 | v9inode->fscache = NULL; |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 233 | spin_lock_init(&v9inode->fscache_lock); |
| 234 | #endif |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 235 | v9inode->writeback_fid = NULL; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 236 | v9inode->cache_validity = 0; |
Aneesh Kumar K.V | 5a7e0a8 | 2011-03-08 16:39:46 +0530 | [diff] [blame] | 237 | mutex_init(&v9inode->v_mutex); |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 238 | return &v9inode->vfs_inode; |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /** |
| 242 | * v9fs_destroy_inode - destroy an inode |
| 243 | * |
| 244 | */ |
| 245 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 246 | static void v9fs_i_callback(struct rcu_head *head) |
| 247 | { |
| 248 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 249 | kmem_cache_free(v9fs_inode_cache, V9FS_I(inode)); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 250 | } |
| 251 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 252 | void v9fs_destroy_inode(struct inode *inode) |
| 253 | { |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 254 | call_rcu(&inode->i_rcu, v9fs_i_callback); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 255 | } |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 256 | |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 257 | int v9fs_init_inode(struct v9fs_session_info *v9ses, |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 258 | struct inode *inode, int mode, dev_t rdev) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 259 | { |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 260 | int err = 0; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 261 | |
Dmitry Monakhov | 217f206 | 2010-03-04 17:30:57 +0300 | [diff] [blame] | 262 | inode_init_owner(inode, NULL, mode); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 263 | inode->i_blocks = 0; |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 264 | inode->i_rdev = rdev; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 265 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 266 | inode->i_mapping->a_ops = &v9fs_addr_operations; |
| 267 | |
| 268 | switch (mode & S_IFMT) { |
| 269 | case S_IFIFO: |
| 270 | case S_IFBLK: |
| 271 | case S_IFCHR: |
| 272 | case S_IFSOCK: |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 273 | if (v9fs_proto_dotl(v9ses)) { |
| 274 | inode->i_op = &v9fs_file_inode_operations_dotl; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 275 | } else if (v9fs_proto_dotu(v9ses)) { |
| 276 | inode->i_op = &v9fs_file_inode_operations; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 277 | } else { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 278 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 279 | "special files without extended mode\n"); |
| 280 | err = -EINVAL; |
| 281 | goto error; |
| 282 | } |
| 283 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 284 | break; |
| 285 | case S_IFREG: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 286 | if (v9fs_proto_dotl(v9ses)) { |
| 287 | inode->i_op = &v9fs_file_inode_operations_dotl; |
Aneesh Kumar K.V | 29236f4 | 2011-02-28 17:03:54 +0530 | [diff] [blame] | 288 | if (v9ses->cache) |
| 289 | inode->i_fop = |
| 290 | &v9fs_cached_file_operations_dotl; |
| 291 | else |
| 292 | inode->i_fop = &v9fs_file_operations_dotl; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 293 | } else { |
| 294 | inode->i_op = &v9fs_file_inode_operations; |
Aneesh Kumar K.V | 29236f4 | 2011-02-28 17:03:54 +0530 | [diff] [blame] | 295 | if (v9ses->cache) |
| 296 | inode->i_fop = &v9fs_cached_file_operations; |
| 297 | else |
| 298 | inode->i_fop = &v9fs_file_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 301 | break; |
| 302 | case S_IFLNK: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 303 | if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) { |
| 304 | P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with " |
| 305 | "legacy protocol.\n"); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 306 | err = -EINVAL; |
| 307 | goto error; |
| 308 | } |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 309 | |
| 310 | if (v9fs_proto_dotl(v9ses)) |
| 311 | inode->i_op = &v9fs_symlink_inode_operations_dotl; |
| 312 | else |
| 313 | inode->i_op = &v9fs_symlink_inode_operations; |
| 314 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 315 | break; |
| 316 | case S_IFDIR: |
| 317 | inc_nlink(inode); |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 318 | if (v9fs_proto_dotl(v9ses)) |
| 319 | inode->i_op = &v9fs_dir_inode_operations_dotl; |
| 320 | else if (v9fs_proto_dotu(v9ses)) |
| 321 | inode->i_op = &v9fs_dir_inode_operations_dotu; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 322 | else |
| 323 | inode->i_op = &v9fs_dir_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 324 | |
| 325 | if (v9fs_proto_dotl(v9ses)) |
| 326 | inode->i_fop = &v9fs_dir_operations_dotl; |
| 327 | else |
| 328 | inode->i_fop = &v9fs_dir_operations; |
| 329 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 330 | break; |
| 331 | default: |
| 332 | P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", |
| 333 | mode, mode & S_IFMT); |
| 334 | err = -EINVAL; |
| 335 | goto error; |
| 336 | } |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 337 | error: |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 338 | return err; |
| 339 | |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * v9fs_get_inode - helper function to setup an inode |
| 344 | * @sb: superblock |
| 345 | * @mode: mode to setup inode with |
| 346 | * |
| 347 | */ |
| 348 | |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 349 | struct inode *v9fs_get_inode(struct super_block *sb, int mode, dev_t rdev) |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 350 | { |
| 351 | int err; |
| 352 | struct inode *inode; |
| 353 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
| 354 | |
| 355 | P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); |
| 356 | |
| 357 | inode = new_inode(sb); |
| 358 | if (!inode) { |
| 359 | P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); |
| 360 | return ERR_PTR(-ENOMEM); |
| 361 | } |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 362 | err = v9fs_init_inode(v9ses, inode, mode, rdev); |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 363 | if (err) { |
| 364 | iput(inode); |
| 365 | return ERR_PTR(err); |
| 366 | } |
| 367 | return inode; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 370 | /* |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 371 | static struct v9fs_fid* |
| 372 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) |
| 373 | { |
| 374 | int err; |
Mika Kukkonen | 736c4b85 | 2006-12-06 20:36:29 -0800 | [diff] [blame] | 375 | int nfid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 376 | struct v9fs_fid *ret; |
| 377 | struct v9fs_fcall *fcall; |
| 378 | |
| 379 | nfid = v9fs_get_idpool(&v9ses->fidpool); |
| 380 | if (nfid < 0) { |
| 381 | eprintk(KERN_WARNING, "no free fids available\n"); |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 382 | return ERR_PTR(-ENOSPC); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name, |
| 386 | &fcall); |
| 387 | |
| 388 | if (err < 0) { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 389 | if (fcall && fcall->id == RWALK) |
| 390 | goto clunk_fid; |
| 391 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 392 | PRINT_FCALL_ERROR("walk error", fcall); |
| 393 | v9fs_put_idpool(nfid, &v9ses->fidpool); |
| 394 | goto error; |
| 395 | } |
| 396 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 397 | kfree(fcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 398 | fcall = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 399 | ret = v9fs_fid_create(v9ses, nfid); |
| 400 | if (!ret) { |
| 401 | err = -ENOMEM; |
| 402 | goto clunk_fid; |
| 403 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 404 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 405 | err = v9fs_fid_insert(ret, dentry); |
| 406 | if (err < 0) { |
| 407 | v9fs_fid_destroy(ret); |
| 408 | goto clunk_fid; |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 409 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 410 | |
| 411 | return ret; |
| 412 | |
| 413 | clunk_fid: |
| 414 | v9fs_t_clunk(v9ses, nfid); |
| 415 | |
| 416 | error: |
| 417 | kfree(fcall); |
| 418 | return ERR_PTR(err); |
| 419 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 420 | */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 421 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * v9fs_clear_inode - release an inode |
| 425 | * @inode: inode to release |
| 426 | * |
| 427 | */ |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 428 | void v9fs_evict_inode(struct inode *inode) |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 429 | { |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 430 | struct v9fs_inode *v9inode = V9FS_I(inode); |
| 431 | |
Al Viro | b57922d | 2010-06-07 14:34:48 -0400 | [diff] [blame] | 432 | truncate_inode_pages(inode->i_mapping, 0); |
| 433 | end_writeback(inode); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 434 | filemap_fdatawrite(inode->i_mapping); |
| 435 | |
| 436 | #ifdef CONFIG_9P_FSCACHE |
| 437 | v9fs_cache_inode_put_cookie(inode); |
| 438 | #endif |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 439 | /* clunk the fid stashed in writeback_fid */ |
| 440 | if (v9inode->writeback_fid) { |
| 441 | p9_client_clunk(v9inode->writeback_fid); |
| 442 | v9inode->writeback_fid = NULL; |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 443 | } |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 444 | } |
| 445 | |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 446 | static int v9fs_test_inode(struct inode *inode, void *data) |
| 447 | { |
| 448 | int umode; |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 449 | dev_t rdev; |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 450 | struct v9fs_inode *v9inode = V9FS_I(inode); |
| 451 | struct p9_wstat *st = (struct p9_wstat *)data; |
| 452 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); |
| 453 | |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 454 | umode = p9mode2unixmode(v9ses, st, &rdev); |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 455 | /* don't match inode of different type */ |
| 456 | if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) |
| 457 | return 0; |
| 458 | |
| 459 | /* compare qid details */ |
| 460 | if (memcmp(&v9inode->qid.version, |
| 461 | &st->qid.version, sizeof(v9inode->qid.version))) |
| 462 | return 0; |
| 463 | |
| 464 | if (v9inode->qid.type != st->qid.type) |
| 465 | return 0; |
| 466 | return 1; |
| 467 | } |
| 468 | |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 469 | static int v9fs_test_new_inode(struct inode *inode, void *data) |
| 470 | { |
| 471 | return 0; |
| 472 | } |
| 473 | |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 474 | static int v9fs_set_inode(struct inode *inode, void *data) |
| 475 | { |
| 476 | struct v9fs_inode *v9inode = V9FS_I(inode); |
| 477 | struct p9_wstat *st = (struct p9_wstat *)data; |
| 478 | |
| 479 | memcpy(&v9inode->qid, &st->qid, sizeof(st->qid)); |
| 480 | return 0; |
| 481 | } |
| 482 | |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 483 | static struct inode *v9fs_qid_iget(struct super_block *sb, |
| 484 | struct p9_qid *qid, |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 485 | struct p9_wstat *st, |
| 486 | int new) |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 487 | { |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 488 | dev_t rdev; |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 489 | int retval, umode; |
| 490 | unsigned long i_ino; |
| 491 | struct inode *inode; |
| 492 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 493 | int (*test)(struct inode *, void *); |
| 494 | |
| 495 | if (new) |
| 496 | test = v9fs_test_new_inode; |
| 497 | else |
| 498 | test = v9fs_test_inode; |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 499 | |
| 500 | i_ino = v9fs_qid2ino(qid); |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 501 | inode = iget5_locked(sb, i_ino, test, v9fs_set_inode, st); |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 502 | if (!inode) |
| 503 | return ERR_PTR(-ENOMEM); |
| 504 | if (!(inode->i_state & I_NEW)) |
| 505 | return inode; |
| 506 | /* |
| 507 | * initialize the inode with the stat info |
| 508 | * FIXME!! we may need support for stale inodes |
| 509 | * later. |
| 510 | */ |
Aneesh Kumar K.V | fd2421f | 2011-07-11 16:40:59 +0000 | [diff] [blame] | 511 | inode->i_ino = i_ino; |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 512 | umode = p9mode2unixmode(v9ses, st, &rdev); |
| 513 | retval = v9fs_init_inode(v9ses, inode, umode, rdev); |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 514 | if (retval) |
| 515 | goto error; |
| 516 | |
| 517 | v9fs_stat2inode(st, inode, sb); |
| 518 | #ifdef CONFIG_9P_FSCACHE |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 519 | v9fs_cache_inode_get_cookie(inode); |
| 520 | #endif |
| 521 | unlock_new_inode(inode); |
| 522 | return inode; |
| 523 | error: |
| 524 | unlock_new_inode(inode); |
| 525 | iput(inode); |
| 526 | return ERR_PTR(retval); |
| 527 | |
| 528 | } |
| 529 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 530 | struct inode * |
Aneesh Kumar K.V | a78ce05 | 2011-02-28 17:04:02 +0530 | [diff] [blame] | 531 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 532 | struct super_block *sb, int new) |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 533 | { |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 534 | struct p9_wstat *st; |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 535 | struct inode *inode = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 536 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 537 | st = p9_client_stat(fid); |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 538 | if (IS_ERR(st)) |
| 539 | return ERR_CAST(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 540 | |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 541 | inode = v9fs_qid_iget(sb, &st->qid, st, new); |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 542 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 543 | kfree(st); |
Aneesh Kumar K.V | 5ffc0cb | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 544 | return inode; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Aneesh Kumar K.V | f88657c | 2011-08-03 19:55:32 +0530 | [diff] [blame] | 548 | * v9fs_at_to_dotl_flags- convert Linux specific AT flags to |
| 549 | * plan 9 AT flag. |
| 550 | * @flags: flags to convert |
| 551 | */ |
| 552 | static int v9fs_at_to_dotl_flags(int flags) |
| 553 | { |
| 554 | int rflags = 0; |
| 555 | if (flags & AT_REMOVEDIR) |
| 556 | rflags |= P9_DOTL_AT_REMOVEDIR; |
| 557 | return rflags; |
| 558 | } |
| 559 | |
| 560 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 561 | * v9fs_remove - helper function to remove files and directories |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 562 | * @dir: directory inode that is being deleted |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 563 | * @dentry: dentry that is being deleted |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 564 | * @rmdir: removing a directory |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 565 | * |
| 566 | */ |
| 567 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 568 | static int v9fs_remove(struct inode *dir, struct dentry *dentry, int flags) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 569 | { |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 570 | struct inode *inode; |
| 571 | int retval = -EOPNOTSUPP; |
| 572 | struct p9_fid *v9fid, *dfid; |
| 573 | struct v9fs_session_info *v9ses; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 574 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 575 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %x\n", |
| 576 | dir, dentry, flags); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 577 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 578 | v9ses = v9fs_inode2v9ses(dir); |
| 579 | inode = dentry->d_inode; |
| 580 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 581 | if (IS_ERR(dfid)) { |
| 582 | retval = PTR_ERR(dfid); |
| 583 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", retval); |
| 584 | return retval; |
| 585 | } |
| 586 | if (v9fs_proto_dotl(v9ses)) |
Aneesh Kumar K.V | f88657c | 2011-08-03 19:55:32 +0530 | [diff] [blame] | 587 | retval = p9_client_unlinkat(dfid, dentry->d_name.name, |
| 588 | v9fs_at_to_dotl_flags(flags)); |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 589 | if (retval == -EOPNOTSUPP) { |
| 590 | /* Try the one based on path */ |
| 591 | v9fid = v9fs_fid_clone(dentry); |
| 592 | if (IS_ERR(v9fid)) |
| 593 | return PTR_ERR(v9fid); |
| 594 | retval = p9_client_remove(v9fid); |
| 595 | } |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 596 | if (!retval) { |
| 597 | /* |
| 598 | * directories on unlink should have zero |
| 599 | * link count |
| 600 | */ |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 601 | if (flags & AT_REMOVEDIR) { |
| 602 | clear_nlink(inode); |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 603 | drop_nlink(dir); |
| 604 | } else |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 605 | drop_nlink(inode); |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 606 | |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 607 | v9fs_invalidate_inode_attr(inode); |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 608 | v9fs_invalidate_inode_attr(dir); |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 609 | } |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 610 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 613 | /** |
| 614 | * v9fs_create - Create a file |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 615 | * @v9ses: session information |
| 616 | * @dir: directory that dentry is being created in |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 617 | * @dentry: dentry that is being created |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 618 | * @extension: 9p2000.u extension string to support devices, etc. |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 619 | * @perm: create permissions |
| 620 | * @mode: open mode |
| 621 | * |
| 622 | */ |
| 623 | static struct p9_fid * |
| 624 | v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, |
| 625 | struct dentry *dentry, char *extension, u32 perm, u8 mode) |
| 626 | { |
| 627 | int err; |
| 628 | char *name; |
| 629 | struct p9_fid *dfid, *ofid, *fid; |
| 630 | struct inode *inode; |
| 631 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 632 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 633 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 634 | err = 0; |
| 635 | ofid = NULL; |
| 636 | fid = NULL; |
| 637 | name = (char *) dentry->d_name.name; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 638 | dfid = v9fs_fid_lookup(dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 639 | if (IS_ERR(dfid)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 640 | err = PTR_ERR(dfid); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 641 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 642 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* clone a fid to use for creation */ |
| 646 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 647 | if (IS_ERR(ofid)) { |
| 648 | err = PTR_ERR(ofid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 649 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 650 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | err = p9_client_fcreate(ofid, name, perm, mode, extension); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 654 | if (err < 0) { |
| 655 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 656 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 657 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 658 | |
| 659 | /* now walk from the parent so we can get unopened fid */ |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 660 | fid = p9_client_walk(dfid, 1, &name, 1); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 661 | if (IS_ERR(fid)) { |
| 662 | err = PTR_ERR(fid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 663 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 664 | fid = NULL; |
| 665 | goto error; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 666 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 667 | |
| 668 | /* instantiate inode and assign the unopened fid to the dentry */ |
Aneesh Kumar K.V | ed80fcf | 2011-07-06 16:32:31 +0530 | [diff] [blame] | 669 | inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 670 | if (IS_ERR(inode)) { |
| 671 | err = PTR_ERR(inode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 672 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 673 | goto error; |
| 674 | } |
Abhishek Kulkarni | 50fb6d2 | 2009-07-19 13:41:57 -0600 | [diff] [blame] | 675 | err = v9fs_fid_add(dentry, fid); |
| 676 | if (err < 0) |
| 677 | goto error; |
Aneesh Kumar K.V | 5441ae5 | 2011-07-25 18:06:32 +0000 | [diff] [blame] | 678 | d_instantiate(dentry, inode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 679 | return ofid; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 680 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 681 | if (ofid) |
| 682 | p9_client_clunk(ofid); |
| 683 | |
| 684 | if (fid) |
| 685 | p9_client_clunk(fid); |
| 686 | |
| 687 | return ERR_PTR(err); |
| 688 | } |
| 689 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 690 | /** |
| 691 | * v9fs_vfs_create - VFS hook to create files |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 692 | * @dir: directory inode that is being created |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 693 | * @dentry: dentry that is being deleted |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 694 | * @mode: create permissions |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 695 | * @nd: path information |
| 696 | * |
| 697 | */ |
| 698 | |
| 699 | static int |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 700 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 701 | struct nameidata *nd) |
| 702 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 703 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 704 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 705 | int flags; |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 706 | struct file *filp; |
| 707 | struct v9fs_inode *v9inode; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 708 | struct v9fs_session_info *v9ses; |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 709 | struct p9_fid *fid, *inode_fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 710 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 711 | err = 0; |
| 712 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 713 | v9ses = v9fs_inode2v9ses(dir); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 714 | perm = unixmode2p9mode(v9ses, mode); |
Al Viro | dd7dd556 | 2011-06-25 21:17:17 -0400 | [diff] [blame] | 715 | if (nd) |
Al Viro | 8a5e929 | 2011-06-25 19:15:54 -0400 | [diff] [blame] | 716 | flags = nd->intent.open.flags; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 717 | else |
| 718 | flags = O_RDWR; |
| 719 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 720 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 721 | v9fs_uflags2omode(flags, |
| 722 | v9fs_proto_dotu(v9ses))); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 723 | if (IS_ERR(fid)) { |
| 724 | err = PTR_ERR(fid); |
| 725 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 726 | goto error; |
| 727 | } |
| 728 | |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 729 | v9fs_invalidate_inode_attr(dir); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 730 | /* if we are opening a file, assign the open fid to the file */ |
Al Viro | dd7dd556 | 2011-06-25 21:17:17 -0400 | [diff] [blame] | 731 | if (nd) { |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 732 | v9inode = V9FS_I(dentry->d_inode); |
Aneesh Kumar K.V | 5a7e0a8 | 2011-03-08 16:39:46 +0530 | [diff] [blame] | 733 | mutex_lock(&v9inode->v_mutex); |
Aneesh Kumar K.V | 7add697 | 2011-03-08 16:39:49 +0530 | [diff] [blame] | 734 | if (v9ses->cache && !v9inode->writeback_fid && |
| 735 | ((flags & O_ACCMODE) != O_RDONLY)) { |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 736 | /* |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 737 | * clone a fid and add it to writeback_fid |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 738 | * we do it during open time instead of |
| 739 | * page dirty time via write_begin/page_mkwrite |
| 740 | * because we want write after unlink usecase |
| 741 | * to work. |
| 742 | */ |
| 743 | inode_fid = v9fs_writeback_fid(dentry); |
| 744 | if (IS_ERR(inode_fid)) { |
| 745 | err = PTR_ERR(inode_fid); |
Aneesh Kumar K.V | 5a7e0a8 | 2011-03-08 16:39:46 +0530 | [diff] [blame] | 746 | mutex_unlock(&v9inode->v_mutex); |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 747 | goto error; |
| 748 | } |
Aneesh Kumar K.V | 6b39f6d | 2011-02-28 17:04:03 +0530 | [diff] [blame] | 749 | v9inode->writeback_fid = (void *) inode_fid; |
Aneesh Kumar K.V | 3cf387d | 2011-02-28 17:03:57 +0530 | [diff] [blame] | 750 | } |
Aneesh Kumar K.V | 5a7e0a8 | 2011-03-08 16:39:46 +0530 | [diff] [blame] | 751 | mutex_unlock(&v9inode->v_mutex); |
Aneesh Kumar K.V | 877cb3d | 2010-09-22 12:42:30 +0530 | [diff] [blame] | 752 | filp = lookup_instantiate_filp(nd, dentry, generic_file_open); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 753 | if (IS_ERR(filp)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 754 | err = PTR_ERR(filp); |
| 755 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 758 | filp->private_data = fid; |
Aneesh Kumar K.V | 46848de | 2011-02-28 17:03:55 +0530 | [diff] [blame] | 759 | #ifdef CONFIG_9P_FSCACHE |
| 760 | if (v9ses->cache) |
| 761 | v9fs_cache_inode_set_cookie(dentry->d_inode, filp); |
| 762 | #endif |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 763 | } else |
| 764 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 765 | |
| 766 | return 0; |
| 767 | |
| 768 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 769 | if (fid) |
| 770 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 771 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 772 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /** |
| 776 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 777 | * @dir: inode that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 778 | * @dentry: dentry that is being unlinked |
| 779 | * @mode: mode for new directory |
| 780 | * |
| 781 | */ |
| 782 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 783 | static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 784 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 785 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 786 | u32 perm; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 787 | struct p9_fid *fid; |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 788 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 789 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 790 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 791 | err = 0; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 792 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 793 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 794 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD); |
| 795 | if (IS_ERR(fid)) { |
| 796 | err = PTR_ERR(fid); |
| 797 | fid = NULL; |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 798 | } else { |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 799 | inc_nlink(dir); |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 800 | v9fs_invalidate_inode_attr(dir); |
| 801 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 802 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 803 | if (fid) |
| 804 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 805 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 806 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /** |
| 810 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode |
| 811 | * @dir: inode that is being walked from |
| 812 | * @dentry: dentry that is being walked to? |
| 813 | * @nameidata: path data |
| 814 | * |
| 815 | */ |
| 816 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 817 | struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 818 | struct nameidata *nameidata) |
| 819 | { |
Aneesh Kumar K.V | 73f5071 | 2011-08-16 22:19:28 +0530 | [diff] [blame] | 820 | struct dentry *res; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 821 | struct super_block *sb; |
| 822 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 823 | struct p9_fid *dfid, *fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 824 | struct inode *inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 825 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 826 | int result = 0; |
| 827 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 828 | 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] | 829 | dir, dentry->d_name.name, dentry, nameidata); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 830 | |
Sripathi Kodi | 11e9b49 | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 831 | if (dentry->d_name.len > NAME_MAX) |
| 832 | return ERR_PTR(-ENAMETOOLONG); |
| 833 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 834 | sb = dir->i_sb; |
| 835 | v9ses = v9fs_inode2v9ses(dir); |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 836 | /* We can walk d_parent because we hold the dir->i_mutex */ |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 837 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 838 | if (IS_ERR(dfid)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 839 | return ERR_CAST(dfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 840 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 841 | name = (char *) dentry->d_name.name; |
| 842 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 843 | if (IS_ERR(fid)) { |
| 844 | result = PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 845 | if (result == -ENOENT) { |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 846 | inode = NULL; |
| 847 | goto inst_out; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 848 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 849 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 850 | return ERR_PTR(result); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 851 | } |
Aneesh Kumar K.V | 73f5071 | 2011-08-16 22:19:28 +0530 | [diff] [blame] | 852 | /* |
| 853 | * Make sure we don't use a wrong inode due to parallel |
| 854 | * unlink. For cached mode create calls request for new |
| 855 | * inode. But with cache disabled, lookup should do this. |
| 856 | */ |
| 857 | if (v9ses->cache) |
| 858 | inode = v9fs_get_inode_from_fid(v9ses, fid, dir->i_sb); |
| 859 | else |
| 860 | inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 861 | if (IS_ERR(inode)) { |
| 862 | result = PTR_ERR(inode); |
| 863 | inode = NULL; |
| 864 | goto error; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 865 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 866 | result = v9fs_fid_add(dentry, fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 867 | if (result < 0) |
Aneesh Kumar K.V | 9856af8 | 2010-09-22 12:24:23 +0530 | [diff] [blame] | 868 | goto error_iput; |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 869 | inst_out: |
Aneesh Kumar K.V | 73f5071 | 2011-08-16 22:19:28 +0530 | [diff] [blame] | 870 | /* |
| 871 | * If we had a rename on the server and a parallel lookup |
| 872 | * for the new name, then make sure we instantiate with |
| 873 | * the new name. ie look up for a/b, while on server somebody |
| 874 | * moved b under k and client parallely did a lookup for |
| 875 | * k/b. |
| 876 | */ |
| 877 | res = d_materialise_unique(dentry, inode); |
| 878 | if (!IS_ERR(res)) |
| 879 | return res; |
| 880 | result = PTR_ERR(res); |
Aneesh Kumar K.V | 9856af8 | 2010-09-22 12:24:23 +0530 | [diff] [blame] | 881 | error_iput: |
| 882 | iput(inode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 883 | error: |
Julien Brunel | 62aa528 | 2008-09-24 16:22:22 -0500 | [diff] [blame] | 884 | p9_client_clunk(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 885 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 886 | return ERR_PTR(result); |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * v9fs_vfs_unlink - VFS unlink hook to delete an inode |
| 891 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 892 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 893 | * |
| 894 | */ |
| 895 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 896 | int v9fs_vfs_unlink(struct inode *i, struct dentry *d) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 897 | { |
| 898 | return v9fs_remove(i, d, 0); |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * v9fs_vfs_rmdir - VFS unlink hook to delete a directory |
| 903 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 904 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 905 | * |
| 906 | */ |
| 907 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 908 | int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 909 | { |
Aneesh Kumar K.V | 48e370f | 2011-06-28 15:41:18 +0530 | [diff] [blame] | 910 | return v9fs_remove(i, d, AT_REMOVEDIR); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /** |
| 914 | * v9fs_vfs_rename - VFS hook to rename an inode |
| 915 | * @old_dir: old dir inode |
| 916 | * @old_dentry: old dentry |
| 917 | * @new_dir: new dir inode |
| 918 | * @new_dentry: new dentry |
| 919 | * |
| 920 | */ |
| 921 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 922 | int |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 923 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 924 | struct inode *new_dir, struct dentry *new_dentry) |
| 925 | { |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 926 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 927 | struct inode *old_inode; |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 928 | struct inode *new_inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 929 | struct v9fs_session_info *v9ses; |
| 930 | struct p9_fid *oldfid; |
| 931 | struct p9_fid *olddirfid; |
| 932 | struct p9_fid *newdirfid; |
| 933 | struct p9_wstat wstat; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 934 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 935 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 936 | retval = 0; |
| 937 | old_inode = old_dentry->d_inode; |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 938 | new_inode = new_dentry->d_inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 939 | v9ses = v9fs_inode2v9ses(old_inode); |
| 940 | oldfid = v9fs_fid_lookup(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 941 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 942 | return PTR_ERR(oldfid); |
| 943 | |
| 944 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 945 | if (IS_ERR(olddirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 946 | retval = PTR_ERR(olddirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 947 | goto done; |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 951 | if (IS_ERR(newdirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 952 | retval = PTR_ERR(newdirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 953 | goto clunk_olddir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 956 | down_write(&v9ses->rename_sem); |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 957 | if (v9fs_proto_dotl(v9ses)) { |
Aneesh Kumar K.V | 9e8fb38 | 2011-06-28 15:41:16 +0530 | [diff] [blame] | 958 | retval = p9_client_renameat(olddirfid, old_dentry->d_name.name, |
| 959 | newdirfid, new_dentry->d_name.name); |
| 960 | if (retval == -EOPNOTSUPP) |
| 961 | retval = p9_client_rename(oldfid, newdirfid, |
| 962 | new_dentry->d_name.name); |
| 963 | if (retval != -EOPNOTSUPP) |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 964 | goto clunk_newdir; |
| 965 | } |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 966 | if (old_dentry->d_parent != new_dentry->d_parent) { |
| 967 | /* |
| 968 | * 9P .u can only handle file rename in the same directory |
| 969 | */ |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 970 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 971 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 972 | "old dir and new dir are different\n"); |
Eric Van Hensbergen | 621997c | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 973 | retval = -EXDEV; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 974 | goto clunk_newdir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 975 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 976 | v9fs_blank_wstat(&wstat); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 977 | wstat.muid = v9ses->uname; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 978 | wstat.name = (char *) new_dentry->d_name.name; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 979 | retval = p9_client_wstat(oldfid, &wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 980 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 981 | clunk_newdir: |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 982 | if (!retval) { |
| 983 | if (new_inode) { |
| 984 | if (S_ISDIR(new_inode->i_mode)) |
| 985 | clear_nlink(new_inode); |
| 986 | else |
| 987 | drop_nlink(new_inode); |
| 988 | } |
| 989 | if (S_ISDIR(old_inode->i_mode)) { |
| 990 | if (!new_inode) |
| 991 | inc_nlink(new_dir); |
| 992 | drop_nlink(old_dir); |
| 993 | } |
Aneesh Kumar K.V | 3bc86de | 2011-02-28 17:04:07 +0530 | [diff] [blame] | 994 | v9fs_invalidate_inode_attr(old_inode); |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 995 | v9fs_invalidate_inode_attr(old_dir); |
| 996 | v9fs_invalidate_inode_attr(new_dir); |
Aneesh Kumar K.V | 3bc86de | 2011-02-28 17:04:07 +0530 | [diff] [blame] | 997 | |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 998 | /* successful rename */ |
| 999 | d_move(old_dentry, new_dentry); |
Aneesh Kumar K.V | b271ec4 | 2011-02-28 17:04:05 +0530 | [diff] [blame] | 1000 | } |
Aneesh Kumar K.V | a534c8d | 2010-06-30 19:18:50 +0530 | [diff] [blame] | 1001 | up_write(&v9ses->rename_sem); |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1002 | p9_client_clunk(newdirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1003 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1004 | clunk_olddir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1005 | p9_client_clunk(olddirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1006 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1007 | done: |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1008 | return retval; |
| 1009 | } |
| 1010 | |
| 1011 | /** |
Adrian Bunk | 943ffb5 | 2006-01-10 00:10:13 +0100 | [diff] [blame] | 1012 | * v9fs_vfs_getattr - retrieve file metadata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1013 | * @mnt: mount information |
| 1014 | * @dentry: file to get attributes on |
| 1015 | * @stat: metadata structure to populate |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1016 | * |
| 1017 | */ |
| 1018 | |
| 1019 | static int |
| 1020 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1021 | struct kstat *stat) |
| 1022 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1023 | int err; |
| 1024 | struct v9fs_session_info *v9ses; |
| 1025 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1026 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1027 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1028 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 1029 | err = -EPERM; |
Aneesh Kumar K.V | 42869c8 | 2011-03-08 16:39:50 +0530 | [diff] [blame] | 1030 | v9ses = v9fs_dentry2v9ses(dentry); |
Aneesh Kumar K.V | a121190 | 2011-02-28 17:04:01 +0530 | [diff] [blame] | 1031 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 1032 | generic_fillattr(dentry->d_inode, stat); |
| 1033 | return 0; |
| 1034 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1035 | fid = v9fs_fid_lookup(dentry); |
| 1036 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1037 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1038 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1039 | st = p9_client_stat(fid); |
| 1040 | if (IS_ERR(st)) |
| 1041 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1042 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1043 | v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1044 | generic_fillattr(dentry->d_inode, stat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1045 | |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1046 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1047 | kfree(st); |
| 1048 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * v9fs_vfs_setattr - set file metadata |
| 1053 | * @dentry: file whose metadata to set |
| 1054 | * @iattr: metadata assignment structure |
| 1055 | * |
| 1056 | */ |
| 1057 | |
| 1058 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 1059 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1060 | int retval; |
| 1061 | struct v9fs_session_info *v9ses; |
| 1062 | struct p9_fid *fid; |
| 1063 | struct p9_wstat wstat; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1064 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1065 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
Aneesh Kumar K.V | 059c138 | 2011-03-08 16:39:48 +0530 | [diff] [blame] | 1066 | retval = inode_change_ok(dentry->d_inode, iattr); |
| 1067 | if (retval) |
| 1068 | return retval; |
| 1069 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1070 | retval = -EPERM; |
Aneesh Kumar K.V | 42869c8 | 2011-03-08 16:39:50 +0530 | [diff] [blame] | 1071 | v9ses = v9fs_dentry2v9ses(dentry); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1072 | fid = v9fs_fid_lookup(dentry); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1073 | if(IS_ERR(fid)) |
| 1074 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1075 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1076 | v9fs_blank_wstat(&wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1077 | if (iattr->ia_valid & ATTR_MODE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1078 | wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1079 | |
| 1080 | if (iattr->ia_valid & ATTR_MTIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1081 | wstat.mtime = iattr->ia_mtime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1082 | |
| 1083 | if (iattr->ia_valid & ATTR_ATIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1084 | wstat.atime = iattr->ia_atime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1085 | |
| 1086 | if (iattr->ia_valid & ATTR_SIZE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1087 | wstat.length = iattr->ia_size; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1088 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1089 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1090 | if (iattr->ia_valid & ATTR_UID) |
| 1091 | wstat.n_uid = iattr->ia_uid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1092 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1093 | if (iattr->ia_valid & ATTR_GID) |
| 1094 | wstat.n_gid = iattr->ia_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1095 | } |
Aneesh Kumar K.V | 059c138 | 2011-03-08 16:39:48 +0530 | [diff] [blame] | 1096 | |
Aneesh Kumar K.V | 3dc5436 | 2011-02-28 17:04:11 +0530 | [diff] [blame] | 1097 | /* Write all dirty data */ |
| 1098 | if (S_ISREG(dentry->d_inode->i_mode)) |
| 1099 | filemap_write_and_wait(dentry->d_inode->i_mapping); |
| 1100 | |
Aneesh Kumar K.V | f10fc50 | 2011-02-28 17:04:10 +0530 | [diff] [blame] | 1101 | retval = p9_client_wstat(fid, &wstat); |
| 1102 | if (retval < 0) |
| 1103 | return retval; |
Aneesh Kumar K.V | 059c138 | 2011-03-08 16:39:48 +0530 | [diff] [blame] | 1104 | |
| 1105 | if ((iattr->ia_valid & ATTR_SIZE) && |
| 1106 | iattr->ia_size != i_size_read(dentry->d_inode)) |
| 1107 | truncate_setsize(dentry->d_inode, iattr->ia_size); |
| 1108 | |
Aneesh Kumar K.V | f10fc50 | 2011-02-28 17:04:10 +0530 | [diff] [blame] | 1109 | v9fs_invalidate_inode_attr(dentry->d_inode); |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 1110 | |
| 1111 | setattr_copy(dentry->d_inode, iattr); |
| 1112 | mark_inode_dirty(dentry->d_inode); |
| 1113 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1117 | * v9fs_stat2inode - populate an inode structure with mistat info |
| 1118 | * @stat: Plan 9 metadata (mistat) structure |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1119 | * @inode: inode to populate |
| 1120 | * @sb: superblock of filesystem |
| 1121 | * |
| 1122 | */ |
| 1123 | |
| 1124 | void |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1125 | v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1126 | struct super_block *sb) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1127 | { |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1128 | mode_t mode; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1129 | char ext[32]; |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1130 | char tag_name[14]; |
| 1131 | unsigned int i_nlink; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1132 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1133 | struct v9fs_inode *v9inode = V9FS_I(inode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1134 | |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 1135 | set_nlink(inode, 1); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1136 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1137 | inode->i_atime.tv_sec = stat->atime; |
| 1138 | inode->i_mtime.tv_sec = stat->mtime; |
| 1139 | inode->i_ctime.tv_sec = stat->mtime; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1140 | |
Latchesar Ionkov | bd32b82 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1141 | inode->i_uid = v9ses->dfltuid; |
| 1142 | inode->i_gid = v9ses->dfltgid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1143 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1144 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1145 | inode->i_uid = stat->n_uid; |
| 1146 | inode->i_gid = stat->n_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1147 | } |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1148 | if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) { |
| 1149 | if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) { |
| 1150 | /* |
| 1151 | * Hadlink support got added later to |
| 1152 | * to the .u extension. So there can be |
| 1153 | * server out there that doesn't support |
| 1154 | * this even with .u extension. So check |
| 1155 | * for non NULL stat->extension |
| 1156 | */ |
| 1157 | strncpy(ext, stat->extension, sizeof(ext)); |
| 1158 | /* HARDLINKCOUNT %u */ |
| 1159 | sscanf(ext, "%13s %u", tag_name, &i_nlink); |
| 1160 | if (!strncmp(tag_name, "HARDLINKCOUNT", 13)) |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 1161 | set_nlink(inode, i_nlink); |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1162 | } |
| 1163 | } |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1164 | mode = stat->mode & S_IALLUGO; |
| 1165 | mode |= inode->i_mode & ~S_IALLUGO; |
| 1166 | inode->i_mode = mode; |
Abhishek Kulkarni | 7549ae3e | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1167 | i_size_write(inode, stat->length); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1168 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1169 | /* not real number of blocks, but 512 byte ones ... */ |
Abhishek Kulkarni | 7549ae3e | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1170 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1171 | v9inode->cache_validity &= ~V9FS_INO_INVALID_ATTR; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * v9fs_qid2ino - convert qid into inode number |
| 1176 | * @qid: qid to hash |
| 1177 | * |
| 1178 | * BUG: potential for inode number collisions? |
| 1179 | */ |
| 1180 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1181 | ino_t v9fs_qid2ino(struct p9_qid *qid) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1182 | { |
| 1183 | u64 path = qid->path + 2; |
| 1184 | ino_t i = 0; |
| 1185 | |
| 1186 | if (sizeof(ino_t) == sizeof(path)) |
| 1187 | memcpy(&i, &path, sizeof(ino_t)); |
| 1188 | else |
| 1189 | i = (ino_t) (path ^ (path >> 32)); |
| 1190 | |
| 1191 | return i; |
| 1192 | } |
| 1193 | |
| 1194 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1195 | * v9fs_readlink - read a symlink's location (internal version) |
| 1196 | * @dentry: dentry for symlink |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1197 | * @buffer: buffer to load symlink location into |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1198 | * @buflen: length of buffer |
| 1199 | * |
| 1200 | */ |
| 1201 | |
| 1202 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 1203 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1204 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1205 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1206 | struct v9fs_session_info *v9ses; |
| 1207 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1208 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1209 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1210 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); |
| 1211 | retval = -EPERM; |
Aneesh Kumar K.V | 42869c8 | 2011-03-08 16:39:50 +0530 | [diff] [blame] | 1212 | v9ses = v9fs_dentry2v9ses(dentry); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1213 | fid = v9fs_fid_lookup(dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1214 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1215 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1216 | |
M. Mohan Kumar | 329176cc | 2010-09-28 19:59:25 +0530 | [diff] [blame] | 1217 | if (!v9fs_proto_dotu(v9ses)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1218 | return -EBADF; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1219 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1220 | st = p9_client_stat(fid); |
| 1221 | if (IS_ERR(st)) |
| 1222 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1223 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1224 | if (!(st->mode & P9_DMSYMLINK)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1225 | retval = -EINVAL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1226 | goto done; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | /* copy extension buffer into buffer */ |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1230 | strncpy(buffer, st->extension, buflen); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1231 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1232 | P9_DPRINTK(P9_DEBUG_VFS, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1233 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1234 | |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1235 | retval = strnlen(buffer, buflen); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1236 | done: |
Latchesar Ionkov | 62b2be5 | 2010-08-24 18:13:59 +0000 | [diff] [blame] | 1237 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1238 | kfree(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1239 | return retval; |
| 1240 | } |
| 1241 | |
| 1242 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1243 | * v9fs_vfs_follow_link - follow a symlink path |
| 1244 | * @dentry: dentry for symlink |
| 1245 | * @nd: nameidata |
| 1246 | * |
| 1247 | */ |
| 1248 | |
| 1249 | static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 1250 | { |
| 1251 | int len = 0; |
| 1252 | char *link = __getname(); |
| 1253 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1254 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1255 | |
| 1256 | if (!link) |
| 1257 | link = ERR_PTR(-ENOMEM); |
| 1258 | else { |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1259 | len = v9fs_readlink(dentry, link, PATH_MAX); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1260 | |
| 1261 | if (len < 0) { |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1262 | __putname(link); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1263 | link = ERR_PTR(len); |
| 1264 | } else |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1265 | link[min(len, PATH_MAX-1)] = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1266 | } |
| 1267 | nd_set_link(nd, link); |
| 1268 | |
| 1269 | return NULL; |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * v9fs_vfs_put_link - release a symlink path |
| 1274 | * @dentry: dentry for symlink |
| 1275 | * @nd: nameidata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1276 | * @p: unused |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1277 | * |
| 1278 | */ |
| 1279 | |
Aneesh Kumar K.V | 53c06f4 | 2011-01-10 13:51:47 -0600 | [diff] [blame] | 1280 | void |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1281 | 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] | 1282 | { |
| 1283 | char *s = nd_get_link(nd); |
| 1284 | |
Duane Griffin | 6ff2320 | 2008-12-19 16:45:21 -0600 | [diff] [blame] | 1285 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, |
| 1286 | IS_ERR(s) ? "<error>" : s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1287 | if (!IS_ERR(s)) |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1288 | __putname(s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1291 | /** |
| 1292 | * v9fs_vfs_mkspecial - create a special file |
| 1293 | * @dir: inode to create special file in |
| 1294 | * @dentry: dentry to create |
| 1295 | * @mode: mode to create special file |
| 1296 | * @extension: 9p2000.u format extension string representing special file |
| 1297 | * |
| 1298 | */ |
| 1299 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1300 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1301 | u32 perm, const char *extension) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1302 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1303 | struct p9_fid *fid; |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 1304 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1305 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1306 | v9ses = v9fs_inode2v9ses(dir); |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1307 | if (!v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1308 | P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1309 | return -EPERM; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1312 | fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm, |
| 1313 | P9_OREAD); |
| 1314 | if (IS_ERR(fid)) |
| 1315 | return PTR_ERR(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1316 | |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 1317 | v9fs_invalidate_inode_attr(dir); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1318 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1319 | return 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * v9fs_vfs_symlink - helper function to create symlinks |
| 1324 | * @dir: directory inode containing symlink |
| 1325 | * @dentry: dentry for symlink |
| 1326 | * @symname: symlink data |
| 1327 | * |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1328 | * See Also: 9P2000.u RFC for more information |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1329 | * |
| 1330 | */ |
| 1331 | |
| 1332 | static int |
| 1333 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) |
| 1334 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1335 | P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, |
| 1336 | dentry->d_name.name, symname); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1337 | |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1338 | return v9fs_vfs_mkspecial(dir, dentry, P9_DMSYMLINK, symname); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1341 | /** |
| 1342 | * v9fs_vfs_link - create a hardlink |
| 1343 | * @old_dentry: dentry for file to link to |
| 1344 | * @dir: inode destination for new link |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1345 | * @dentry: dentry for link |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1346 | * |
| 1347 | */ |
| 1348 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1349 | static int |
| 1350 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1351 | struct dentry *dentry) |
| 1352 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1353 | int retval; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1354 | char *name; |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 1355 | struct p9_fid *oldfid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1356 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1357 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1358 | " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1359 | old_dentry->d_name.name); |
| 1360 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1361 | oldfid = v9fs_fid_clone(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1362 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1363 | return PTR_ERR(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1364 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1365 | name = __getname(); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1366 | if (unlikely(!name)) { |
| 1367 | retval = -ENOMEM; |
| 1368 | goto clunk_fid; |
| 1369 | } |
Florin Malita | 0710d36 | 2006-06-25 05:48:31 -0700 | [diff] [blame] | 1370 | |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1371 | sprintf(name, "%d\n", oldfid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1372 | retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1373 | __putname(name); |
Aneesh Kumar K.V | c06c066 | 2011-02-28 17:04:09 +0530 | [diff] [blame] | 1374 | if (!retval) { |
| 1375 | v9fs_refresh_inode(oldfid, old_dentry->d_inode); |
Aneesh Kumar K.V | d28c61f | 2011-02-28 17:04:08 +0530 | [diff] [blame] | 1376 | v9fs_invalidate_inode_attr(dir); |
Aneesh Kumar K.V | c06c066 | 2011-02-28 17:04:09 +0530 | [diff] [blame] | 1377 | } |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1378 | clunk_fid: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1379 | p9_client_clunk(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1380 | return retval; |
| 1381 | } |
| 1382 | |
| 1383 | /** |
| 1384 | * v9fs_vfs_mknod - create a special file |
| 1385 | * @dir: inode destination for new link |
| 1386 | * @dentry: dentry for file |
| 1387 | * @mode: mode for creation |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1388 | * @rdev: device associated with special file |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1389 | * |
| 1390 | */ |
| 1391 | |
| 1392 | static int |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 1393 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1394 | { |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1395 | struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1396 | int retval; |
| 1397 | char *name; |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1398 | u32 perm; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1399 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1400 | P9_DPRINTK(P9_DEBUG_VFS, |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1401 | " %lu,%s mode: %hx MAJOR: %u MINOR: %u\n", dir->i_ino, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1402 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1403 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1404 | if (!new_valid_dev(rdev)) |
| 1405 | return -EINVAL; |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1406 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1407 | name = __getname(); |
Eugene Teo | c0291a0 | 2006-03-25 03:07:27 -0800 | [diff] [blame] | 1408 | if (!name) |
| 1409 | return -ENOMEM; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1410 | /* build extension */ |
| 1411 | if (S_ISBLK(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1412 | sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1413 | else if (S_ISCHR(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1414 | sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1415 | else if (S_ISFIFO(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1416 | *name = 0; |
Venkateswararao Jujjuri | 75cc5c9 | 2010-05-22 12:20:30 -0500 | [diff] [blame] | 1417 | else if (S_ISSOCK(mode)) |
| 1418 | *name = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1419 | else { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1420 | __putname(name); |
| 1421 | return -EINVAL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Al Viro | c2837de | 2011-07-24 18:59:07 -0400 | [diff] [blame^] | 1424 | perm = unixmode2p9mode(v9ses, mode); |
| 1425 | retval = v9fs_vfs_mkspecial(dir, dentry, perm, name); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1426 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1427 | |
| 1428 | return retval; |
| 1429 | } |
| 1430 | |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1431 | int v9fs_refresh_inode(struct p9_fid *fid, struct inode *inode) |
| 1432 | { |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1433 | int umode; |
| 1434 | dev_t rdev; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1435 | loff_t i_size; |
| 1436 | struct p9_wstat *st; |
| 1437 | struct v9fs_session_info *v9ses; |
| 1438 | |
| 1439 | v9ses = v9fs_inode2v9ses(inode); |
| 1440 | st = p9_client_stat(fid); |
| 1441 | if (IS_ERR(st)) |
| 1442 | return PTR_ERR(st); |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1443 | /* |
| 1444 | * Don't update inode if the file type is different |
| 1445 | */ |
| 1446 | umode = p9mode2unixmode(v9ses, st, &rdev); |
| 1447 | if ((inode->i_mode & S_IFMT) != (umode & S_IFMT)) |
| 1448 | goto out; |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1449 | |
| 1450 | spin_lock(&inode->i_lock); |
| 1451 | /* |
| 1452 | * We don't want to refresh inode->i_size, |
| 1453 | * because we may have cached data |
| 1454 | */ |
| 1455 | i_size = inode->i_size; |
| 1456 | v9fs_stat2inode(st, inode, inode->i_sb); |
| 1457 | if (v9ses->cache) |
| 1458 | inode->i_size = i_size; |
| 1459 | spin_unlock(&inode->i_lock); |
Aneesh Kumar K.V | 4508914 | 2011-07-25 18:06:33 +0000 | [diff] [blame] | 1460 | out: |
Aneesh Kumar K.V | b3cbea0 | 2011-02-28 17:04:06 +0530 | [diff] [blame] | 1461 | p9stat_free(st); |
| 1462 | kfree(st); |
| 1463 | return 0; |
| 1464 | } |
| 1465 | |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1466 | static const struct inode_operations v9fs_dir_inode_operations_dotu = { |
| 1467 | .create = v9fs_vfs_create, |
| 1468 | .lookup = v9fs_vfs_lookup, |
| 1469 | .symlink = v9fs_vfs_symlink, |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1470 | .link = v9fs_vfs_link, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1471 | .unlink = v9fs_vfs_unlink, |
| 1472 | .mkdir = v9fs_vfs_mkdir, |
| 1473 | .rmdir = v9fs_vfs_rmdir, |
Aneesh Kumar K.V | 1d76e31 | 2010-08-30 17:43:07 +0000 | [diff] [blame] | 1474 | .mknod = v9fs_vfs_mknod, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1475 | .rename = v9fs_vfs_rename, |
| 1476 | .getattr = v9fs_vfs_getattr, |
| 1477 | .setattr = v9fs_vfs_setattr, |
| 1478 | }; |
| 1479 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1480 | static const struct inode_operations v9fs_dir_inode_operations = { |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 1481 | .create = v9fs_vfs_create, |
| 1482 | .lookup = v9fs_vfs_lookup, |
| 1483 | .unlink = v9fs_vfs_unlink, |
| 1484 | .mkdir = v9fs_vfs_mkdir, |
| 1485 | .rmdir = v9fs_vfs_rmdir, |
| 1486 | .mknod = v9fs_vfs_mknod, |
| 1487 | .rename = v9fs_vfs_rename, |
| 1488 | .getattr = v9fs_vfs_getattr, |
| 1489 | .setattr = v9fs_vfs_setattr, |
| 1490 | }; |
| 1491 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1492 | static const struct inode_operations v9fs_file_inode_operations = { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1493 | .getattr = v9fs_vfs_getattr, |
| 1494 | .setattr = v9fs_vfs_setattr, |
| 1495 | }; |
| 1496 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1497 | static const struct inode_operations v9fs_symlink_inode_operations = { |
Al Viro | 204f2f0 | 2009-12-23 00:35:54 -0500 | [diff] [blame] | 1498 | .readlink = generic_readlink, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1499 | .follow_link = v9fs_vfs_follow_link, |
| 1500 | .put_link = v9fs_vfs_put_link, |
| 1501 | .getattr = v9fs_vfs_getattr, |
| 1502 | .setattr = v9fs_vfs_setattr, |
| 1503 | }; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1504 | |