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