~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/fuse/dir.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/fuse/dir.c (Version linux-6.11.5) and /fs/fuse/dir.c (Version linux-5.12.19)


  1 /*                                                  1 /*
  2   FUSE: Filesystem in Userspace                     2   FUSE: Filesystem in Userspace
  3   Copyright (C) 2001-2008  Miklos Szeredi <mik      3   Copyright (C) 2001-2008  Miklos Szeredi <miklos@szeredi.hu>
  4                                                     4 
  5   This program can be distributed under the te      5   This program can be distributed under the terms of the GNU GPL.
  6   See the file COPYING.                             6   See the file COPYING.
  7 */                                                  7 */
  8                                                     8 
  9 #include "fuse_i.h"                                 9 #include "fuse_i.h"
 10                                                    10 
 11 #include <linux/pagemap.h>                         11 #include <linux/pagemap.h>
 12 #include <linux/file.h>                            12 #include <linux/file.h>
 13 #include <linux/fs_context.h>                      13 #include <linux/fs_context.h>
 14 #include <linux/moduleparam.h>                 << 
 15 #include <linux/sched.h>                           14 #include <linux/sched.h>
 16 #include <linux/namei.h>                           15 #include <linux/namei.h>
 17 #include <linux/slab.h>                            16 #include <linux/slab.h>
 18 #include <linux/xattr.h>                           17 #include <linux/xattr.h>
 19 #include <linux/iversion.h>                        18 #include <linux/iversion.h>
 20 #include <linux/posix_acl.h>                       19 #include <linux/posix_acl.h>
 21 #include <linux/security.h>                    << 
 22 #include <linux/types.h>                       << 
 23 #include <linux/kernel.h>                      << 
 24                                                << 
 25 static bool __read_mostly allow_sys_admin_acce << 
 26 module_param(allow_sys_admin_access, bool, 064 << 
 27 MODULE_PARM_DESC(allow_sys_admin_access,       << 
 28                  "Allow users with CAP_SYS_ADM << 
 29                                                    20 
 30 static void fuse_advise_use_readdirplus(struct     21 static void fuse_advise_use_readdirplus(struct inode *dir)
 31 {                                                  22 {
 32         struct fuse_inode *fi = get_fuse_inode     23         struct fuse_inode *fi = get_fuse_inode(dir);
 33                                                    24 
 34         set_bit(FUSE_I_ADVISE_RDPLUS, &fi->sta     25         set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
 35 }                                                  26 }
 36                                                    27 
 37 #if BITS_PER_LONG >= 64                            28 #if BITS_PER_LONG >= 64
 38 static inline void __fuse_dentry_settime(struc     29 static inline void __fuse_dentry_settime(struct dentry *entry, u64 time)
 39 {                                                  30 {
 40         entry->d_fsdata = (void *) time;           31         entry->d_fsdata = (void *) time;
 41 }                                                  32 }
 42                                                    33 
 43 static inline u64 fuse_dentry_time(const struc     34 static inline u64 fuse_dentry_time(const struct dentry *entry)
 44 {                                                  35 {
 45         return (u64)entry->d_fsdata;               36         return (u64)entry->d_fsdata;
 46 }                                                  37 }
 47                                                    38 
 48 #else                                              39 #else
 49 union fuse_dentry {                                40 union fuse_dentry {
 50         u64 time;                                  41         u64 time;
 51         struct rcu_head rcu;                       42         struct rcu_head rcu;
 52 };                                                 43 };
 53                                                    44 
 54 static inline void __fuse_dentry_settime(struc     45 static inline void __fuse_dentry_settime(struct dentry *dentry, u64 time)
 55 {                                                  46 {
 56         ((union fuse_dentry *) dentry->d_fsdat     47         ((union fuse_dentry *) dentry->d_fsdata)->time = time;
 57 }                                                  48 }
 58                                                    49 
 59 static inline u64 fuse_dentry_time(const struc     50 static inline u64 fuse_dentry_time(const struct dentry *entry)
 60 {                                                  51 {
 61         return ((union fuse_dentry *) entry->d     52         return ((union fuse_dentry *) entry->d_fsdata)->time;
 62 }                                                  53 }
 63 #endif                                             54 #endif
 64                                                    55 
 65 static void fuse_dentry_settime(struct dentry      56 static void fuse_dentry_settime(struct dentry *dentry, u64 time)
 66 {                                                  57 {
 67         struct fuse_conn *fc = get_fuse_conn_s     58         struct fuse_conn *fc = get_fuse_conn_super(dentry->d_sb);
 68         bool delete = !time && fc->delete_stal     59         bool delete = !time && fc->delete_stale;
 69         /*                                         60         /*
 70          * Mess with DCACHE_OP_DELETE because      61          * Mess with DCACHE_OP_DELETE because dput() will be faster without it.
 71          * Don't care about races, either way      62          * Don't care about races, either way it's just an optimization
 72          */                                        63          */
 73         if ((!delete && (dentry->d_flags & DCA     64         if ((!delete && (dentry->d_flags & DCACHE_OP_DELETE)) ||
 74             (delete && !(dentry->d_flags & DCA     65             (delete && !(dentry->d_flags & DCACHE_OP_DELETE))) {
 75                 spin_lock(&dentry->d_lock);        66                 spin_lock(&dentry->d_lock);
 76                 if (!delete)                       67                 if (!delete)
 77                         dentry->d_flags &= ~DC     68                         dentry->d_flags &= ~DCACHE_OP_DELETE;
 78                 else                               69                 else
 79                         dentry->d_flags |= DCA     70                         dentry->d_flags |= DCACHE_OP_DELETE;
 80                 spin_unlock(&dentry->d_lock);      71                 spin_unlock(&dentry->d_lock);
 81         }                                          72         }
 82                                                    73 
 83         __fuse_dentry_settime(dentry, time);       74         __fuse_dentry_settime(dentry, time);
 84 }                                                  75 }
 85                                                    76 
 86 /*                                                 77 /*
 87  * FUSE caches dentries and attributes with se     78  * FUSE caches dentries and attributes with separate timeout.  The
 88  * time in jiffies until the dentry/attributes     79  * time in jiffies until the dentry/attributes are valid is stored in
 89  * dentry->d_fsdata and fuse_inode->i_time res     80  * dentry->d_fsdata and fuse_inode->i_time respectively.
 90  */                                                81  */
 91                                                    82 
 92 /*                                                 83 /*
 93  * Calculate the time in jiffies until a dentr     84  * Calculate the time in jiffies until a dentry/attributes are valid
 94  */                                                85  */
 95 u64 fuse_time_to_jiffies(u64 sec, u32 nsec)    !!  86 static u64 time_to_jiffies(u64 sec, u32 nsec)
 96 {                                                  87 {
 97         if (sec || nsec) {                         88         if (sec || nsec) {
 98                 struct timespec64 ts = {           89                 struct timespec64 ts = {
 99                         sec,                       90                         sec,
100                         min_t(u32, nsec, NSEC_     91                         min_t(u32, nsec, NSEC_PER_SEC - 1)
101                 };                                 92                 };
102                                                    93 
103                 return get_jiffies_64() + time     94                 return get_jiffies_64() + timespec64_to_jiffies(&ts);
104         } else                                     95         } else
105                 return 0;                          96                 return 0;
106 }                                                  97 }
107                                                    98 
108 /*                                                 99 /*
109  * Set dentry and possibly attribute timeouts     100  * Set dentry and possibly attribute timeouts from the lookup/mk*
110  * replies                                        101  * replies
111  */                                               102  */
112 void fuse_change_entry_timeout(struct dentry *    103 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o)
113 {                                                 104 {
114         fuse_dentry_settime(entry,                105         fuse_dentry_settime(entry,
115                 fuse_time_to_jiffies(o->entry_ !! 106                 time_to_jiffies(o->entry_valid, o->entry_valid_nsec));
116 }                                                 107 }
117                                                   108 
118 void fuse_invalidate_attr_mask(struct inode *i !! 109 static u64 attr_timeout(struct fuse_attr_out *o)
                                                   >> 110 {
                                                   >> 111         return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
                                                   >> 112 }
                                                   >> 113 
                                                   >> 114 u64 entry_attr_timeout(struct fuse_entry_out *o)
                                                   >> 115 {
                                                   >> 116         return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
                                                   >> 117 }
                                                   >> 118 
                                                   >> 119 static void fuse_invalidate_attr_mask(struct inode *inode, u32 mask)
119 {                                                 120 {
120         set_mask_bits(&get_fuse_inode(inode)->    121         set_mask_bits(&get_fuse_inode(inode)->inval_mask, 0, mask);
121 }                                                 122 }
122                                                   123 
123 /*                                                124 /*
124  * Mark the attributes as stale, so that at th    125  * Mark the attributes as stale, so that at the next call to
125  * ->getattr() they will be fetched from users    126  * ->getattr() they will be fetched from userspace
126  */                                               127  */
127 void fuse_invalidate_attr(struct inode *inode)    128 void fuse_invalidate_attr(struct inode *inode)
128 {                                                 129 {
129         fuse_invalidate_attr_mask(inode, STATX    130         fuse_invalidate_attr_mask(inode, STATX_BASIC_STATS);
130 }                                                 131 }
131                                                   132 
132 static void fuse_dir_changed(struct inode *dir    133 static void fuse_dir_changed(struct inode *dir)
133 {                                                 134 {
134         fuse_invalidate_attr(dir);                135         fuse_invalidate_attr(dir);
135         inode_maybe_inc_iversion(dir, false);     136         inode_maybe_inc_iversion(dir, false);
136 }                                                 137 }
137                                                   138 
138 /*                                             !! 139 /**
139  * Mark the attributes as stale due to an atim    140  * Mark the attributes as stale due to an atime change.  Avoid the invalidate if
140  * atime is not used.                             141  * atime is not used.
141  */                                               142  */
142 void fuse_invalidate_atime(struct inode *inode    143 void fuse_invalidate_atime(struct inode *inode)
143 {                                                 144 {
144         if (!IS_RDONLY(inode))                    145         if (!IS_RDONLY(inode))
145                 fuse_invalidate_attr_mask(inod    146                 fuse_invalidate_attr_mask(inode, STATX_ATIME);
146 }                                                 147 }
147                                                   148 
148 /*                                                149 /*
149  * Just mark the entry as stale, so that a nex    150  * Just mark the entry as stale, so that a next attempt to look it up
150  * will result in a new lookup call to userspa    151  * will result in a new lookup call to userspace
151  *                                                152  *
152  * This is called when a dentry is about to be    153  * This is called when a dentry is about to become negative and the
153  * timeout is unknown (unlink, rmdir, rename a    154  * timeout is unknown (unlink, rmdir, rename and in some cases
154  * lookup)                                        155  * lookup)
155  */                                               156  */
156 void fuse_invalidate_entry_cache(struct dentry    157 void fuse_invalidate_entry_cache(struct dentry *entry)
157 {                                                 158 {
158         fuse_dentry_settime(entry, 0);            159         fuse_dentry_settime(entry, 0);
159 }                                                 160 }
160                                                   161 
161 /*                                                162 /*
162  * Same as fuse_invalidate_entry_cache(), but     163  * Same as fuse_invalidate_entry_cache(), but also try to remove the
163  * dentry from the hash                           164  * dentry from the hash
164  */                                               165  */
165 static void fuse_invalidate_entry(struct dentr    166 static void fuse_invalidate_entry(struct dentry *entry)
166 {                                                 167 {
167         d_invalidate(entry);                      168         d_invalidate(entry);
168         fuse_invalidate_entry_cache(entry);       169         fuse_invalidate_entry_cache(entry);
169 }                                                 170 }
170                                                   171 
171 static void fuse_lookup_init(struct fuse_conn     172 static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args,
172                              u64 nodeid, const    173                              u64 nodeid, const struct qstr *name,
173                              struct fuse_entry    174                              struct fuse_entry_out *outarg)
174 {                                                 175 {
175         memset(outarg, 0, sizeof(struct fuse_e    176         memset(outarg, 0, sizeof(struct fuse_entry_out));
176         args->opcode = FUSE_LOOKUP;               177         args->opcode = FUSE_LOOKUP;
177         args->nodeid = nodeid;                    178         args->nodeid = nodeid;
178         args->in_numargs = 1;                     179         args->in_numargs = 1;
179         args->in_args[0].size = name->len + 1;    180         args->in_args[0].size = name->len + 1;
180         args->in_args[0].value = name->name;      181         args->in_args[0].value = name->name;
181         args->out_numargs = 1;                    182         args->out_numargs = 1;
182         args->out_args[0].size = sizeof(struct    183         args->out_args[0].size = sizeof(struct fuse_entry_out);
183         args->out_args[0].value = outarg;         184         args->out_args[0].value = outarg;
184 }                                                 185 }
185                                                   186 
186 /*                                                187 /*
187  * Check whether the dentry is still valid        188  * Check whether the dentry is still valid
188  *                                                189  *
189  * If the entry validity timeout has expired a    190  * If the entry validity timeout has expired and the dentry is
190  * positive, try to redo the lookup.  If the l    191  * positive, try to redo the lookup.  If the lookup results in a
191  * different inode, then let the VFS invalidat    192  * different inode, then let the VFS invalidate the dentry and redo
192  * the lookup once more.  If the lookup result    193  * the lookup once more.  If the lookup results in the same inode,
193  * then refresh the attributes, timeouts and m    194  * then refresh the attributes, timeouts and mark the dentry valid.
194  */                                               195  */
195 static int fuse_dentry_revalidate(struct dentr    196 static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
196 {                                                 197 {
197         struct inode *inode;                      198         struct inode *inode;
198         struct dentry *parent;                    199         struct dentry *parent;
199         struct fuse_mount *fm;                    200         struct fuse_mount *fm;
200         struct fuse_inode *fi;                    201         struct fuse_inode *fi;
201         int ret;                                  202         int ret;
202                                                   203 
203         inode = d_inode_rcu(entry);               204         inode = d_inode_rcu(entry);
204         if (inode && fuse_is_bad(inode))          205         if (inode && fuse_is_bad(inode))
205                 goto invalid;                     206                 goto invalid;
206         else if (time_before64(fuse_dentry_tim    207         else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
207                  (flags & (LOOKUP_EXCL | LOOKU !! 208                  (flags & (LOOKUP_EXCL | LOOKUP_REVAL))) {
208                 struct fuse_entry_out outarg;     209                 struct fuse_entry_out outarg;
209                 FUSE_ARGS(args);                  210                 FUSE_ARGS(args);
210                 struct fuse_forget_link *forge    211                 struct fuse_forget_link *forget;
211                 u64 attr_version;                 212                 u64 attr_version;
212                                                   213 
213                 /* For negative dentries, alwa    214                 /* For negative dentries, always do a fresh lookup */
214                 if (!inode)                       215                 if (!inode)
215                         goto invalid;             216                         goto invalid;
216                                                   217 
217                 ret = -ECHILD;                    218                 ret = -ECHILD;
218                 if (flags & LOOKUP_RCU)           219                 if (flags & LOOKUP_RCU)
219                         goto out;                 220                         goto out;
220                                                   221 
221                 fm = get_fuse_mount(inode);       222                 fm = get_fuse_mount(inode);
222                                                   223 
223                 forget = fuse_alloc_forget();     224                 forget = fuse_alloc_forget();
224                 ret = -ENOMEM;                    225                 ret = -ENOMEM;
225                 if (!forget)                      226                 if (!forget)
226                         goto out;                 227                         goto out;
227                                                   228 
228                 attr_version = fuse_get_attr_v    229                 attr_version = fuse_get_attr_version(fm->fc);
229                                                   230 
230                 parent = dget_parent(entry);      231                 parent = dget_parent(entry);
231                 fuse_lookup_init(fm->fc, &args    232                 fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)),
232                                  &entry->d_nam    233                                  &entry->d_name, &outarg);
233                 ret = fuse_simple_request(fm,     234                 ret = fuse_simple_request(fm, &args);
234                 dput(parent);                     235                 dput(parent);
235                 /* Zero nodeid is same as -ENO    236                 /* Zero nodeid is same as -ENOENT */
236                 if (!ret && !outarg.nodeid)       237                 if (!ret && !outarg.nodeid)
237                         ret = -ENOENT;            238                         ret = -ENOENT;
238                 if (!ret) {                       239                 if (!ret) {
239                         fi = get_fuse_inode(in    240                         fi = get_fuse_inode(inode);
240                         if (outarg.nodeid != g    241                         if (outarg.nodeid != get_node_id(inode) ||
241                             (bool) IS_AUTOMOUN    242                             (bool) IS_AUTOMOUNT(inode) != (bool) (outarg.attr.flags & FUSE_ATTR_SUBMOUNT)) {
242                                 fuse_queue_for    243                                 fuse_queue_forget(fm->fc, forget,
243                                                   244                                                   outarg.nodeid, 1);
244                                 goto invalid;     245                                 goto invalid;
245                         }                         246                         }
246                         spin_lock(&fi->lock);     247                         spin_lock(&fi->lock);
247                         fi->nlookup++;            248                         fi->nlookup++;
248                         spin_unlock(&fi->lock)    249                         spin_unlock(&fi->lock);
249                 }                                 250                 }
250                 kfree(forget);                    251                 kfree(forget);
251                 if (ret == -ENOMEM || ret == - !! 252                 if (ret == -ENOMEM)
252                         goto out;                 253                         goto out;
253                 if (ret || fuse_invalid_attr(&    254                 if (ret || fuse_invalid_attr(&outarg.attr) ||
254                     fuse_stale_inode(inode, ou !! 255                     (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
255                         goto invalid;             256                         goto invalid;
256                                                   257 
257                 forget_all_cached_acls(inode);    258                 forget_all_cached_acls(inode);
258                 fuse_change_attributes(inode,  !! 259                 fuse_change_attributes(inode, &outarg.attr,
259                                        ATTR_TI !! 260                                        entry_attr_timeout(&outarg),
260                                        attr_ve    261                                        attr_version);
261                 fuse_change_entry_timeout(entr    262                 fuse_change_entry_timeout(entry, &outarg);
262         } else if (inode) {                       263         } else if (inode) {
263                 fi = get_fuse_inode(inode);       264                 fi = get_fuse_inode(inode);
264                 if (flags & LOOKUP_RCU) {         265                 if (flags & LOOKUP_RCU) {
265                         if (test_bit(FUSE_I_IN    266                         if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
266                                 return -ECHILD    267                                 return -ECHILD;
267                 } else if (test_and_clear_bit(    268                 } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
268                         parent = dget_parent(e    269                         parent = dget_parent(entry);
269                         fuse_advise_use_readdi    270                         fuse_advise_use_readdirplus(d_inode(parent));
270                         dput(parent);             271                         dput(parent);
271                 }                                 272                 }
272         }                                         273         }
273         ret = 1;                                  274         ret = 1;
274 out:                                              275 out:
275         return ret;                               276         return ret;
276                                                   277 
277 invalid:                                          278 invalid:
278         ret = 0;                                  279         ret = 0;
279         goto out;                                 280         goto out;
280 }                                                 281 }
281                                                   282 
282 #if BITS_PER_LONG < 64                            283 #if BITS_PER_LONG < 64
283 static int fuse_dentry_init(struct dentry *den    284 static int fuse_dentry_init(struct dentry *dentry)
284 {                                                 285 {
285         dentry->d_fsdata = kzalloc(sizeof(unio    286         dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry),
286                                    GFP_KERNEL_    287                                    GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE);
287                                                   288 
288         return dentry->d_fsdata ? 0 : -ENOMEM;    289         return dentry->d_fsdata ? 0 : -ENOMEM;
289 }                                                 290 }
290 static void fuse_dentry_release(struct dentry     291 static void fuse_dentry_release(struct dentry *dentry)
291 {                                                 292 {
292         union fuse_dentry *fd = dentry->d_fsda    293         union fuse_dentry *fd = dentry->d_fsdata;
293                                                   294 
294         kfree_rcu(fd, rcu);                       295         kfree_rcu(fd, rcu);
295 }                                                 296 }
296 #endif                                            297 #endif
297                                                   298 
298 static int fuse_dentry_delete(const struct den    299 static int fuse_dentry_delete(const struct dentry *dentry)
299 {                                                 300 {
300         return time_before64(fuse_dentry_time(    301         return time_before64(fuse_dentry_time(dentry), get_jiffies_64());
301 }                                                 302 }
302                                                   303 
303 /*                                                304 /*
304  * Create a fuse_mount object with a new super    305  * Create a fuse_mount object with a new superblock (with path->dentry
305  * as the root), and return that mount so it c    306  * as the root), and return that mount so it can be auto-mounted on
306  * @path.                                         307  * @path.
307  */                                               308  */
308 static struct vfsmount *fuse_dentry_automount(    309 static struct vfsmount *fuse_dentry_automount(struct path *path)
309 {                                                 310 {
310         struct fs_context *fsc;                   311         struct fs_context *fsc;
                                                   >> 312         struct fuse_mount *parent_fm = get_fuse_mount_super(path->mnt->mnt_sb);
                                                   >> 313         struct fuse_conn *fc = parent_fm->fc;
                                                   >> 314         struct fuse_mount *fm;
311         struct vfsmount *mnt;                     315         struct vfsmount *mnt;
312         struct fuse_inode *mp_fi = get_fuse_in    316         struct fuse_inode *mp_fi = get_fuse_inode(d_inode(path->dentry));
                                                   >> 317         struct super_block *sb;
                                                   >> 318         int err;
313                                                   319 
314         fsc = fs_context_for_submount(path->mn    320         fsc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry);
315         if (IS_ERR(fsc))                       !! 321         if (IS_ERR(fsc)) {
316                 return ERR_CAST(fsc);          !! 322                 err = PTR_ERR(fsc);
                                                   >> 323                 goto out;
                                                   >> 324         }
317                                                   325 
318         /* Pass the FUSE inode of the mount fo !! 326         err = -ENOMEM;
319         fsc->fs_private = mp_fi;               !! 327         fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
                                                   >> 328         if (!fm)
                                                   >> 329                 goto out_put_fsc;
                                                   >> 330 
                                                   >> 331         fsc->s_fs_info = fm;
                                                   >> 332         sb = sget_fc(fsc, NULL, set_anon_super_fc);
                                                   >> 333         if (IS_ERR(sb)) {
                                                   >> 334                 err = PTR_ERR(sb);
                                                   >> 335                 kfree(fm);
                                                   >> 336                 goto out_put_fsc;
                                                   >> 337         }
                                                   >> 338         fm->fc = fuse_conn_get(fc);
320                                                   339 
321         /* Create the submount */              !! 340         /* Initialize superblock, making @mp_fi its root */
322         mnt = fc_mount(fsc);                   !! 341         err = fuse_fill_super_submount(sb, mp_fi);
323         if (!IS_ERR(mnt))                      !! 342         if (err) {
324                 mntget(mnt);                   !! 343                 fuse_conn_put(fc);
                                                   >> 344                 kfree(fm);
                                                   >> 345                 sb->s_fs_info = NULL;
                                                   >> 346                 goto out_put_sb;
                                                   >> 347         }
                                                   >> 348 
                                                   >> 349         down_write(&fc->killsb);
                                                   >> 350         list_add_tail(&fm->fc_entry, &fc->mounts);
                                                   >> 351         up_write(&fc->killsb);
                                                   >> 352 
                                                   >> 353         sb->s_flags |= SB_ACTIVE;
                                                   >> 354         fsc->root = dget(sb->s_root);
                                                   >> 355 
                                                   >> 356         /*
                                                   >> 357          * FIXME: setting SB_BORN requires a write barrier for
                                                   >> 358          *        super_cache_count(). We should actually come
                                                   >> 359          *        up with a proper ->get_tree() implementation
                                                   >> 360          *        for submounts and call vfs_get_tree() to take
                                                   >> 361          *        care of the write barrier.
                                                   >> 362          */
                                                   >> 363         smp_wmb();
                                                   >> 364         sb->s_flags |= SB_BORN;
325                                                   365 
                                                   >> 366         /* We are done configuring the superblock, so unlock it */
                                                   >> 367         up_write(&sb->s_umount);
                                                   >> 368 
                                                   >> 369         /* Create the submount */
                                                   >> 370         mnt = vfs_create_mount(fsc);
                                                   >> 371         if (IS_ERR(mnt)) {
                                                   >> 372                 err = PTR_ERR(mnt);
                                                   >> 373                 goto out_put_fsc;
                                                   >> 374         }
                                                   >> 375         mntget(mnt);
326         put_fs_context(fsc);                      376         put_fs_context(fsc);
327         return mnt;                               377         return mnt;
                                                   >> 378 
                                                   >> 379 out_put_sb:
                                                   >> 380         /*
                                                   >> 381          * Only jump here when fsc->root is NULL and sb is still locked
                                                   >> 382          * (otherwise put_fs_context() will put the superblock)
                                                   >> 383          */
                                                   >> 384         deactivate_locked_super(sb);
                                                   >> 385 out_put_fsc:
                                                   >> 386         put_fs_context(fsc);
                                                   >> 387 out:
                                                   >> 388         return ERR_PTR(err);
328 }                                                 389 }
329                                                   390 
330 const struct dentry_operations fuse_dentry_ope    391 const struct dentry_operations fuse_dentry_operations = {
331         .d_revalidate   = fuse_dentry_revalida    392         .d_revalidate   = fuse_dentry_revalidate,
332         .d_delete       = fuse_dentry_delete,     393         .d_delete       = fuse_dentry_delete,
333 #if BITS_PER_LONG < 64                            394 #if BITS_PER_LONG < 64
334         .d_init         = fuse_dentry_init,       395         .d_init         = fuse_dentry_init,
335         .d_release      = fuse_dentry_release,    396         .d_release      = fuse_dentry_release,
336 #endif                                            397 #endif
337         .d_automount    = fuse_dentry_automoun    398         .d_automount    = fuse_dentry_automount,
338 };                                                399 };
339                                                   400 
340 const struct dentry_operations fuse_root_dentr    401 const struct dentry_operations fuse_root_dentry_operations = {
341 #if BITS_PER_LONG < 64                            402 #if BITS_PER_LONG < 64
342         .d_init         = fuse_dentry_init,       403         .d_init         = fuse_dentry_init,
343         .d_release      = fuse_dentry_release,    404         .d_release      = fuse_dentry_release,
344 #endif                                            405 #endif
345 };                                                406 };
346                                                   407 
347 int fuse_valid_type(int m)                        408 int fuse_valid_type(int m)
348 {                                                 409 {
349         return S_ISREG(m) || S_ISDIR(m) || S_I    410         return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
350                 S_ISBLK(m) || S_ISFIFO(m) || S    411                 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
351 }                                                 412 }
352                                                   413 
353 static bool fuse_valid_size(u64 size)          << 
354 {                                              << 
355         return size <= LLONG_MAX;              << 
356 }                                              << 
357                                                << 
358 bool fuse_invalid_attr(struct fuse_attr *attr)    414 bool fuse_invalid_attr(struct fuse_attr *attr)
359 {                                                 415 {
360         return !fuse_valid_type(attr->mode) || !! 416         return !fuse_valid_type(attr->mode) ||
                                                   >> 417                 attr->size > LLONG_MAX;
361 }                                                 418 }
362                                                   419 
363 int fuse_lookup_name(struct super_block *sb, u    420 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
364                      struct fuse_entry_out *ou    421                      struct fuse_entry_out *outarg, struct inode **inode)
365 {                                                 422 {
366         struct fuse_mount *fm = get_fuse_mount    423         struct fuse_mount *fm = get_fuse_mount_super(sb);
367         FUSE_ARGS(args);                          424         FUSE_ARGS(args);
368         struct fuse_forget_link *forget;          425         struct fuse_forget_link *forget;
369         u64 attr_version;                         426         u64 attr_version;
370         int err;                                  427         int err;
371                                                   428 
372         *inode = NULL;                            429         *inode = NULL;
373         err = -ENAMETOOLONG;                      430         err = -ENAMETOOLONG;
374         if (name->len > FUSE_NAME_MAX)            431         if (name->len > FUSE_NAME_MAX)
375                 goto out;                         432                 goto out;
376                                                   433 
377                                                   434 
378         forget = fuse_alloc_forget();             435         forget = fuse_alloc_forget();
379         err = -ENOMEM;                            436         err = -ENOMEM;
380         if (!forget)                              437         if (!forget)
381                 goto out;                         438                 goto out;
382                                                   439 
383         attr_version = fuse_get_attr_version(f    440         attr_version = fuse_get_attr_version(fm->fc);
384                                                   441 
385         fuse_lookup_init(fm->fc, &args, nodeid    442         fuse_lookup_init(fm->fc, &args, nodeid, name, outarg);
386         err = fuse_simple_request(fm, &args);     443         err = fuse_simple_request(fm, &args);
387         /* Zero nodeid is same as -ENOENT, but    444         /* Zero nodeid is same as -ENOENT, but with valid timeout */
388         if (err || !outarg->nodeid)               445         if (err || !outarg->nodeid)
389                 goto out_put_forget;              446                 goto out_put_forget;
390                                                   447 
391         err = -EIO;                               448         err = -EIO;
                                                   >> 449         if (!outarg->nodeid)
                                                   >> 450                 goto out_put_forget;
392         if (fuse_invalid_attr(&outarg->attr))     451         if (fuse_invalid_attr(&outarg->attr))
393                 goto out_put_forget;              452                 goto out_put_forget;
394         if (outarg->nodeid == FUSE_ROOT_ID &&  << 
395                 pr_warn_once("root generation  << 
396                 outarg->generation = 0;        << 
397         }                                      << 
398                                                   453 
399         *inode = fuse_iget(sb, outarg->nodeid,    454         *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
400                            &outarg->attr, ATTR !! 455                            &outarg->attr, entry_attr_timeout(outarg),
401                            attr_version);         456                            attr_version);
402         err = -ENOMEM;                            457         err = -ENOMEM;
403         if (!*inode) {                            458         if (!*inode) {
404                 fuse_queue_forget(fm->fc, forg    459                 fuse_queue_forget(fm->fc, forget, outarg->nodeid, 1);
405                 goto out;                         460                 goto out;
406         }                                         461         }
407         err = 0;                                  462         err = 0;
408                                                   463 
409  out_put_forget:                                  464  out_put_forget:
410         kfree(forget);                            465         kfree(forget);
411  out:                                             466  out:
412         return err;                               467         return err;
413 }                                                 468 }
414                                                   469 
415 static struct dentry *fuse_lookup(struct inode    470 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
416                                   unsigned int    471                                   unsigned int flags)
417 {                                                 472 {
418         int err;                                  473         int err;
419         struct fuse_entry_out outarg;             474         struct fuse_entry_out outarg;
420         struct inode *inode;                      475         struct inode *inode;
421         struct dentry *newent;                    476         struct dentry *newent;
422         bool outarg_valid = true;                 477         bool outarg_valid = true;
423         bool locked;                              478         bool locked;
424                                                   479 
425         if (fuse_is_bad(dir))                     480         if (fuse_is_bad(dir))
426                 return ERR_PTR(-EIO);             481                 return ERR_PTR(-EIO);
427                                                   482 
428         locked = fuse_lock_inode(dir);            483         locked = fuse_lock_inode(dir);
429         err = fuse_lookup_name(dir->i_sb, get_    484         err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
430                                &outarg, &inode    485                                &outarg, &inode);
431         fuse_unlock_inode(dir, locked);           486         fuse_unlock_inode(dir, locked);
432         if (err == -ENOENT) {                     487         if (err == -ENOENT) {
433                 outarg_valid = false;             488                 outarg_valid = false;
434                 err = 0;                          489                 err = 0;
435         }                                         490         }
436         if (err)                                  491         if (err)
437                 goto out_err;                     492                 goto out_err;
438                                                   493 
439         err = -EIO;                               494         err = -EIO;
440         if (inode && get_node_id(inode) == FUS    495         if (inode && get_node_id(inode) == FUSE_ROOT_ID)
441                 goto out_iput;                    496                 goto out_iput;
442                                                   497 
443         newent = d_splice_alias(inode, entry);    498         newent = d_splice_alias(inode, entry);
444         err = PTR_ERR(newent);                    499         err = PTR_ERR(newent);
445         if (IS_ERR(newent))                       500         if (IS_ERR(newent))
446                 goto out_err;                     501                 goto out_err;
447                                                   502 
448         entry = newent ? newent : entry;          503         entry = newent ? newent : entry;
449         if (outarg_valid)                         504         if (outarg_valid)
450                 fuse_change_entry_timeout(entr    505                 fuse_change_entry_timeout(entry, &outarg);
451         else                                      506         else
452                 fuse_invalidate_entry_cache(en    507                 fuse_invalidate_entry_cache(entry);
453                                                   508 
454         if (inode)                                509         if (inode)
455                 fuse_advise_use_readdirplus(di    510                 fuse_advise_use_readdirplus(dir);
456         return newent;                            511         return newent;
457                                                   512 
458  out_iput:                                        513  out_iput:
459         iput(inode);                              514         iput(inode);
460  out_err:                                         515  out_err:
461         return ERR_PTR(err);                      516         return ERR_PTR(err);
462 }                                                 517 }
463                                                   518 
464 static int get_security_context(struct dentry  << 
465                                 struct fuse_in << 
466 {                                              << 
467         struct fuse_secctx *fctx;              << 
468         struct fuse_secctx_header *header;     << 
469         void *ctx = NULL, *ptr;                << 
470         u32 ctxlen, total_len = sizeof(*header << 
471         int err, nr_ctx = 0;                   << 
472         const char *name;                      << 
473         size_t namelen;                        << 
474                                                << 
475         err = security_dentry_init_security(en << 
476                                             &n << 
477         if (err) {                             << 
478                 if (err != -EOPNOTSUPP)        << 
479                         goto out_err;          << 
480                 /* No LSM is supporting this s << 
481                 ctxlen = 0;                    << 
482                 ctx = NULL;                    << 
483         }                                      << 
484                                                << 
485         if (ctxlen) {                          << 
486                 nr_ctx = 1;                    << 
487                 namelen = strlen(name) + 1;    << 
488                 err = -EIO;                    << 
489                 if (WARN_ON(namelen > XATTR_NA << 
490                         goto out_err;          << 
491                 total_len += FUSE_REC_ALIGN(si << 
492         }                                      << 
493                                                << 
494         err = -ENOMEM;                         << 
495         header = ptr = kzalloc(total_len, GFP_ << 
496         if (!ptr)                              << 
497                 goto out_err;                  << 
498                                                << 
499         header->nr_secctx = nr_ctx;            << 
500         header->size = total_len;              << 
501         ptr += sizeof(*header);                << 
502         if (nr_ctx) {                          << 
503                 fctx = ptr;                    << 
504                 fctx->size = ctxlen;           << 
505                 ptr += sizeof(*fctx);          << 
506                                                << 
507                 strcpy(ptr, name);             << 
508                 ptr += namelen;                << 
509                                                << 
510                 memcpy(ptr, ctx, ctxlen);      << 
511         }                                      << 
512         ext->size = total_len;                 << 
513         ext->value = header;                   << 
514         err = 0;                               << 
515 out_err:                                       << 
516         kfree(ctx);                            << 
517         return err;                            << 
518 }                                              << 
519                                                << 
520 static void *extend_arg(struct fuse_in_arg *bu << 
521 {                                              << 
522         void *p;                               << 
523         u32 newlen = buf->size + bytes;        << 
524                                                << 
525         p = krealloc(buf->value, newlen, GFP_K << 
526         if (!p) {                              << 
527                 kfree(buf->value);             << 
528                 buf->size = 0;                 << 
529                 buf->value = NULL;             << 
530                 return NULL;                   << 
531         }                                      << 
532                                                << 
533         memset(p + buf->size, 0, bytes);       << 
534         buf->value = p;                        << 
535         buf->size = newlen;                    << 
536                                                << 
537         return p + newlen - bytes;             << 
538 }                                              << 
539                                                << 
540 static u32 fuse_ext_size(size_t size)          << 
541 {                                              << 
542         return FUSE_REC_ALIGN(sizeof(struct fu << 
543 }                                              << 
544                                                << 
545 /*                                             << 
546  * This adds just a single supplementary group << 
547  */                                            << 
548 static int get_create_supp_group(struct inode  << 
549 {                                              << 
550         struct fuse_conn *fc = get_fuse_conn(d << 
551         struct fuse_ext_header *xh;            << 
552         struct fuse_supp_groups *sg;           << 
553         kgid_t kgid = dir->i_gid;              << 
554         gid_t parent_gid = from_kgid(fc->user_ << 
555         u32 sg_len = fuse_ext_size(sizeof(*sg) << 
556                                                << 
557         if (parent_gid == (gid_t) -1 || gid_eq << 
558             !in_group_p(kgid))                 << 
559                 return 0;                      << 
560                                                << 
561         xh = extend_arg(ext, sg_len);          << 
562         if (!xh)                               << 
563                 return -ENOMEM;                << 
564                                                << 
565         xh->size = sg_len;                     << 
566         xh->type = FUSE_EXT_GROUPS;            << 
567                                                << 
568         sg = (struct fuse_supp_groups *) &xh[1 << 
569         sg->nr_groups = 1;                     << 
570         sg->groups[0] = parent_gid;            << 
571                                                << 
572         return 0;                              << 
573 }                                              << 
574                                                << 
575 static int get_create_ext(struct fuse_args *ar << 
576                           struct inode *dir, s << 
577                           umode_t mode)        << 
578 {                                              << 
579         struct fuse_conn *fc = get_fuse_conn_s << 
580         struct fuse_in_arg ext = { .size = 0,  << 
581         int err = 0;                           << 
582                                                << 
583         if (fc->init_security)                 << 
584                 err = get_security_context(den << 
585         if (!err && fc->create_supp_group)     << 
586                 err = get_create_supp_group(di << 
587                                                << 
588         if (!err && ext.size) {                << 
589                 WARN_ON(args->in_numargs >= AR << 
590                 args->is_ext = true;           << 
591                 args->ext_idx = args->in_numar << 
592                 args->in_args[args->ext_idx] = << 
593         } else {                               << 
594                 kfree(ext.value);              << 
595         }                                      << 
596                                                << 
597         return err;                            << 
598 }                                              << 
599                                                << 
600 static void free_ext_value(struct fuse_args *a << 
601 {                                              << 
602         if (args->is_ext)                      << 
603                 kfree(args->in_args[args->ext_ << 
604 }                                              << 
605                                                << 
606 /*                                                519 /*
607  * Atomic create+open operation                   520  * Atomic create+open operation
608  *                                                521  *
609  * If the filesystem doesn't support this, the    522  * If the filesystem doesn't support this, then fall back to separate
610  * 'mknod' + 'open' requests.                     523  * 'mknod' + 'open' requests.
611  */                                               524  */
612 static int fuse_create_open(struct inode *dir,    525 static int fuse_create_open(struct inode *dir, struct dentry *entry,
613                             struct file *file, !! 526                             struct file *file, unsigned flags,
614                             umode_t mode, u32  !! 527                             umode_t mode)
615 {                                                 528 {
616         int err;                                  529         int err;
617         struct inode *inode;                      530         struct inode *inode;
618         struct fuse_mount *fm = get_fuse_mount    531         struct fuse_mount *fm = get_fuse_mount(dir);
619         FUSE_ARGS(args);                          532         FUSE_ARGS(args);
620         struct fuse_forget_link *forget;          533         struct fuse_forget_link *forget;
621         struct fuse_create_in inarg;              534         struct fuse_create_in inarg;
622         struct fuse_open_out *outopenp;        !! 535         struct fuse_open_out outopen;
623         struct fuse_entry_out outentry;           536         struct fuse_entry_out outentry;
624         struct fuse_inode *fi;                    537         struct fuse_inode *fi;
625         struct fuse_file *ff;                     538         struct fuse_file *ff;
626         bool trunc = flags & O_TRUNC;          << 
627                                                   539 
628         /* Userspace expects S_IFREG in create    540         /* Userspace expects S_IFREG in create mode */
629         BUG_ON((mode & S_IFMT) != S_IFREG);       541         BUG_ON((mode & S_IFMT) != S_IFREG);
630                                                   542 
631         forget = fuse_alloc_forget();             543         forget = fuse_alloc_forget();
632         err = -ENOMEM;                            544         err = -ENOMEM;
633         if (!forget)                              545         if (!forget)
634                 goto out_err;                     546                 goto out_err;
635                                                   547 
636         err = -ENOMEM;                            548         err = -ENOMEM;
637         ff = fuse_file_alloc(fm, true);        !! 549         ff = fuse_file_alloc(fm);
638         if (!ff)                                  550         if (!ff)
639                 goto out_put_forget_req;          551                 goto out_put_forget_req;
640                                                   552 
641         if (!fm->fc->dont_mask)                   553         if (!fm->fc->dont_mask)
642                 mode &= ~current_umask();         554                 mode &= ~current_umask();
643                                                   555 
644         flags &= ~O_NOCTTY;                       556         flags &= ~O_NOCTTY;
645         memset(&inarg, 0, sizeof(inarg));         557         memset(&inarg, 0, sizeof(inarg));
646         memset(&outentry, 0, sizeof(outentry))    558         memset(&outentry, 0, sizeof(outentry));
647         inarg.flags = flags;                      559         inarg.flags = flags;
648         inarg.mode = mode;                        560         inarg.mode = mode;
649         inarg.umask = current_umask();            561         inarg.umask = current_umask();
650                                                   562 
651         if (fm->fc->handle_killpriv_v2 && trun !! 563         if (fm->fc->handle_killpriv_v2 && (flags & O_TRUNC) &&
652             !(flags & O_EXCL) && !capable(CAP_    564             !(flags & O_EXCL) && !capable(CAP_FSETID)) {
653                 inarg.open_flags |= FUSE_OPEN_    565                 inarg.open_flags |= FUSE_OPEN_KILL_SUIDGID;
654         }                                         566         }
655                                                   567 
656         args.opcode = opcode;                  !! 568         args.opcode = FUSE_CREATE;
657         args.nodeid = get_node_id(dir);           569         args.nodeid = get_node_id(dir);
658         args.in_numargs = 2;                      570         args.in_numargs = 2;
659         args.in_args[0].size = sizeof(inarg);     571         args.in_args[0].size = sizeof(inarg);
660         args.in_args[0].value = &inarg;           572         args.in_args[0].value = &inarg;
661         args.in_args[1].size = entry->d_name.l    573         args.in_args[1].size = entry->d_name.len + 1;
662         args.in_args[1].value = entry->d_name.    574         args.in_args[1].value = entry->d_name.name;
663         args.out_numargs = 2;                     575         args.out_numargs = 2;
664         args.out_args[0].size = sizeof(outentr    576         args.out_args[0].size = sizeof(outentry);
665         args.out_args[0].value = &outentry;       577         args.out_args[0].value = &outentry;
666         /* Store outarg for fuse_finish_open() !! 578         args.out_args[1].size = sizeof(outopen);
667         outopenp = &ff->args->open_outarg;     !! 579         args.out_args[1].value = &outopen;
668         args.out_args[1].size = sizeof(*outope << 
669         args.out_args[1].value = outopenp;     << 
670                                                << 
671         err = get_create_ext(&args, dir, entry << 
672         if (err)                               << 
673                 goto out_free_ff;              << 
674                                                << 
675         err = fuse_simple_request(fm, &args);     580         err = fuse_simple_request(fm, &args);
676         free_ext_value(&args);                 << 
677         if (err)                                  581         if (err)
678                 goto out_free_ff;                 582                 goto out_free_ff;
679                                                   583 
680         err = -EIO;                               584         err = -EIO;
681         if (!S_ISREG(outentry.attr.mode) || in    585         if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) ||
682             fuse_invalid_attr(&outentry.attr))    586             fuse_invalid_attr(&outentry.attr))
683                 goto out_free_ff;                 587                 goto out_free_ff;
684                                                   588 
685         ff->fh = outopenp->fh;                 !! 589         ff->fh = outopen.fh;
686         ff->nodeid = outentry.nodeid;             590         ff->nodeid = outentry.nodeid;
687         ff->open_flags = outopenp->open_flags; !! 591         ff->open_flags = outopen.open_flags;
688         inode = fuse_iget(dir->i_sb, outentry.    592         inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
689                           &outentry.attr, ATTR !! 593                           &outentry.attr, entry_attr_timeout(&outentry), 0);
690         if (!inode) {                             594         if (!inode) {
691                 flags &= ~(O_CREAT | O_EXCL |     595                 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
692                 fuse_sync_release(NULL, ff, fl    596                 fuse_sync_release(NULL, ff, flags);
693                 fuse_queue_forget(fm->fc, forg    597                 fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
694                 err = -ENOMEM;                    598                 err = -ENOMEM;
695                 goto out_err;                     599                 goto out_err;
696         }                                         600         }
697         kfree(forget);                            601         kfree(forget);
698         d_instantiate(entry, inode);              602         d_instantiate(entry, inode);
699         fuse_change_entry_timeout(entry, &oute    603         fuse_change_entry_timeout(entry, &outentry);
700         fuse_dir_changed(dir);                    604         fuse_dir_changed(dir);
701         err = generic_file_open(inode, file);  !! 605         err = finish_open(file, entry, generic_file_open);
702         if (!err) {                            << 
703                 file->private_data = ff;       << 
704                 err = finish_open(file, entry, << 
705         }                                      << 
706         if (err) {                                606         if (err) {
707                 fi = get_fuse_inode(inode);       607                 fi = get_fuse_inode(inode);
708                 fuse_sync_release(fi, ff, flag    608                 fuse_sync_release(fi, ff, flags);
709         } else {                                  609         } else {
710                 if (fm->fc->atomic_o_trunc &&  !! 610                 file->private_data = ff;
711                         truncate_pagecache(ino !! 611                 fuse_finish_open(inode, file);
712                 else if (!(ff->open_flags & FO << 
713                         invalidate_inode_pages << 
714         }                                         612         }
715         return err;                               613         return err;
716                                                   614 
717 out_free_ff:                                      615 out_free_ff:
718         fuse_file_free(ff);                       616         fuse_file_free(ff);
719 out_put_forget_req:                               617 out_put_forget_req:
720         kfree(forget);                            618         kfree(forget);
721 out_err:                                          619 out_err:
722         return err;                               620         return err;
723 }                                                 621 }
724                                                   622 
725 static int fuse_mknod(struct mnt_idmap *, stru !! 623 static int fuse_mknod(struct user_namespace *, struct inode *, struct dentry *,
726                       umode_t, dev_t);            624                       umode_t, dev_t);
727 static int fuse_atomic_open(struct inode *dir,    625 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
728                             struct file *file,    626                             struct file *file, unsigned flags,
729                             umode_t mode)         627                             umode_t mode)
730 {                                                 628 {
731         int err;                                  629         int err;
732         struct fuse_conn *fc = get_fuse_conn(d    630         struct fuse_conn *fc = get_fuse_conn(dir);
733         struct dentry *res = NULL;                631         struct dentry *res = NULL;
734                                                   632 
735         if (fuse_is_bad(dir))                     633         if (fuse_is_bad(dir))
736                 return -EIO;                      634                 return -EIO;
737                                                   635 
738         if (d_in_lookup(entry)) {                 636         if (d_in_lookup(entry)) {
739                 res = fuse_lookup(dir, entry,     637                 res = fuse_lookup(dir, entry, 0);
740                 if (IS_ERR(res))                  638                 if (IS_ERR(res))
741                         return PTR_ERR(res);      639                         return PTR_ERR(res);
742                                                   640 
743                 if (res)                          641                 if (res)
744                         entry = res;              642                         entry = res;
745         }                                         643         }
746                                                   644 
747         if (!(flags & O_CREAT) || d_really_is_    645         if (!(flags & O_CREAT) || d_really_is_positive(entry))
748                 goto no_open;                     646                 goto no_open;
749                                                   647 
750         /* Only creates */                        648         /* Only creates */
751         file->f_mode |= FMODE_CREATED;            649         file->f_mode |= FMODE_CREATED;
752                                                   650 
753         if (fc->no_create)                        651         if (fc->no_create)
754                 goto mknod;                       652                 goto mknod;
755                                                   653 
756         err = fuse_create_open(dir, entry, fil !! 654         err = fuse_create_open(dir, entry, file, flags, mode);
757         if (err == -ENOSYS) {                     655         if (err == -ENOSYS) {
758                 fc->no_create = 1;                656                 fc->no_create = 1;
759                 goto mknod;                       657                 goto mknod;
760         } else if (err == -EEXIST)             !! 658         }
761                 fuse_invalidate_entry(entry);  << 
762 out_dput:                                         659 out_dput:
763         dput(res);                                660         dput(res);
764         return err;                               661         return err;
765                                                   662 
766 mknod:                                            663 mknod:
767         err = fuse_mknod(&nop_mnt_idmap, dir,  !! 664         err = fuse_mknod(&init_user_ns, dir, entry, mode, 0);
768         if (err)                                  665         if (err)
769                 goto out_dput;                    666                 goto out_dput;
770 no_open:                                          667 no_open:
771         return finish_no_open(file, res);         668         return finish_no_open(file, res);
772 }                                                 669 }
773                                                   670 
774 /*                                                671 /*
775  * Code shared between mknod, mkdir, symlink a    672  * Code shared between mknod, mkdir, symlink and link
776  */                                               673  */
777 static int create_new_entry(struct fuse_mount     674 static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args,
778                             struct inode *dir,    675                             struct inode *dir, struct dentry *entry,
779                             umode_t mode)         676                             umode_t mode)
780 {                                                 677 {
781         struct fuse_entry_out outarg;             678         struct fuse_entry_out outarg;
782         struct inode *inode;                      679         struct inode *inode;
783         struct dentry *d;                         680         struct dentry *d;
784         int err;                                  681         int err;
785         struct fuse_forget_link *forget;          682         struct fuse_forget_link *forget;
786                                                   683 
787         if (fuse_is_bad(dir))                     684         if (fuse_is_bad(dir))
788                 return -EIO;                      685                 return -EIO;
789                                                   686 
790         forget = fuse_alloc_forget();             687         forget = fuse_alloc_forget();
791         if (!forget)                              688         if (!forget)
792                 return -ENOMEM;                   689                 return -ENOMEM;
793                                                   690 
794         memset(&outarg, 0, sizeof(outarg));       691         memset(&outarg, 0, sizeof(outarg));
795         args->nodeid = get_node_id(dir);          692         args->nodeid = get_node_id(dir);
796         args->out_numargs = 1;                    693         args->out_numargs = 1;
797         args->out_args[0].size = sizeof(outarg    694         args->out_args[0].size = sizeof(outarg);
798         args->out_args[0].value = &outarg;        695         args->out_args[0].value = &outarg;
799                                                << 
800         if (args->opcode != FUSE_LINK) {       << 
801                 err = get_create_ext(args, dir << 
802                 if (err)                       << 
803                         goto out_put_forget_re << 
804         }                                      << 
805                                                << 
806         err = fuse_simple_request(fm, args);      696         err = fuse_simple_request(fm, args);
807         free_ext_value(args);                  << 
808         if (err)                                  697         if (err)
809                 goto out_put_forget_req;          698                 goto out_put_forget_req;
810                                                   699 
811         err = -EIO;                               700         err = -EIO;
812         if (invalid_nodeid(outarg.nodeid) || f    701         if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr))
813                 goto out_put_forget_req;          702                 goto out_put_forget_req;
814                                                   703 
815         if ((outarg.attr.mode ^ mode) & S_IFMT    704         if ((outarg.attr.mode ^ mode) & S_IFMT)
816                 goto out_put_forget_req;          705                 goto out_put_forget_req;
817                                                   706 
818         inode = fuse_iget(dir->i_sb, outarg.no    707         inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
819                           &outarg.attr, ATTR_T !! 708                           &outarg.attr, entry_attr_timeout(&outarg), 0);
820         if (!inode) {                             709         if (!inode) {
821                 fuse_queue_forget(fm->fc, forg    710                 fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1);
822                 return -ENOMEM;                   711                 return -ENOMEM;
823         }                                         712         }
824         kfree(forget);                            713         kfree(forget);
825                                                   714 
826         d_drop(entry);                            715         d_drop(entry);
827         d = d_splice_alias(inode, entry);         716         d = d_splice_alias(inode, entry);
828         if (IS_ERR(d))                            717         if (IS_ERR(d))
829                 return PTR_ERR(d);                718                 return PTR_ERR(d);
830                                                   719 
831         if (d) {                                  720         if (d) {
832                 fuse_change_entry_timeout(d, &    721                 fuse_change_entry_timeout(d, &outarg);
833                 dput(d);                          722                 dput(d);
834         } else {                                  723         } else {
835                 fuse_change_entry_timeout(entr    724                 fuse_change_entry_timeout(entry, &outarg);
836         }                                         725         }
837         fuse_dir_changed(dir);                    726         fuse_dir_changed(dir);
838         return 0;                                 727         return 0;
839                                                   728 
840  out_put_forget_req:                              729  out_put_forget_req:
841         if (err == -EEXIST)                    << 
842                 fuse_invalidate_entry(entry);  << 
843         kfree(forget);                            730         kfree(forget);
844         return err;                               731         return err;
845 }                                                 732 }
846                                                   733 
847 static int fuse_mknod(struct mnt_idmap *idmap, !! 734 static int fuse_mknod(struct user_namespace *mnt_userns, struct inode *dir,
848                       struct dentry *entry, um    735                       struct dentry *entry, umode_t mode, dev_t rdev)
849 {                                                 736 {
850         struct fuse_mknod_in inarg;               737         struct fuse_mknod_in inarg;
851         struct fuse_mount *fm = get_fuse_mount    738         struct fuse_mount *fm = get_fuse_mount(dir);
852         FUSE_ARGS(args);                          739         FUSE_ARGS(args);
853                                                   740 
854         if (!fm->fc->dont_mask)                   741         if (!fm->fc->dont_mask)
855                 mode &= ~current_umask();         742                 mode &= ~current_umask();
856                                                   743 
857         memset(&inarg, 0, sizeof(inarg));         744         memset(&inarg, 0, sizeof(inarg));
858         inarg.mode = mode;                        745         inarg.mode = mode;
859         inarg.rdev = new_encode_dev(rdev);        746         inarg.rdev = new_encode_dev(rdev);
860         inarg.umask = current_umask();            747         inarg.umask = current_umask();
861         args.opcode = FUSE_MKNOD;                 748         args.opcode = FUSE_MKNOD;
862         args.in_numargs = 2;                      749         args.in_numargs = 2;
863         args.in_args[0].size = sizeof(inarg);     750         args.in_args[0].size = sizeof(inarg);
864         args.in_args[0].value = &inarg;           751         args.in_args[0].value = &inarg;
865         args.in_args[1].size = entry->d_name.l    752         args.in_args[1].size = entry->d_name.len + 1;
866         args.in_args[1].value = entry->d_name.    753         args.in_args[1].value = entry->d_name.name;
867         return create_new_entry(fm, &args, dir    754         return create_new_entry(fm, &args, dir, entry, mode);
868 }                                                 755 }
869                                                   756 
870 static int fuse_create(struct mnt_idmap *idmap !! 757 static int fuse_create(struct user_namespace *mnt_userns, struct inode *dir,
871                        struct dentry *entry, u    758                        struct dentry *entry, umode_t mode, bool excl)
872 {                                                 759 {
873         return fuse_mknod(&nop_mnt_idmap, dir, !! 760         return fuse_mknod(&init_user_ns, dir, entry, mode, 0);
874 }                                                 761 }
875                                                   762 
876 static int fuse_tmpfile(struct mnt_idmap *idma !! 763 static int fuse_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
877                         struct file *file, umo << 
878 {                                              << 
879         struct fuse_conn *fc = get_fuse_conn(d << 
880         int err;                               << 
881                                                << 
882         if (fc->no_tmpfile)                    << 
883                 return -EOPNOTSUPP;            << 
884                                                << 
885         err = fuse_create_open(dir, file->f_pa << 
886         if (err == -ENOSYS) {                  << 
887                 fc->no_tmpfile = 1;            << 
888                 err = -EOPNOTSUPP;             << 
889         }                                      << 
890         return err;                            << 
891 }                                              << 
892                                                << 
893 static int fuse_mkdir(struct mnt_idmap *idmap, << 
894                       struct dentry *entry, um    764                       struct dentry *entry, umode_t mode)
895 {                                                 765 {
896         struct fuse_mkdir_in inarg;               766         struct fuse_mkdir_in inarg;
897         struct fuse_mount *fm = get_fuse_mount    767         struct fuse_mount *fm = get_fuse_mount(dir);
898         FUSE_ARGS(args);                          768         FUSE_ARGS(args);
899                                                   769 
900         if (!fm->fc->dont_mask)                   770         if (!fm->fc->dont_mask)
901                 mode &= ~current_umask();         771                 mode &= ~current_umask();
902                                                   772 
903         memset(&inarg, 0, sizeof(inarg));         773         memset(&inarg, 0, sizeof(inarg));
904         inarg.mode = mode;                        774         inarg.mode = mode;
905         inarg.umask = current_umask();            775         inarg.umask = current_umask();
906         args.opcode = FUSE_MKDIR;                 776         args.opcode = FUSE_MKDIR;
907         args.in_numargs = 2;                      777         args.in_numargs = 2;
908         args.in_args[0].size = sizeof(inarg);     778         args.in_args[0].size = sizeof(inarg);
909         args.in_args[0].value = &inarg;           779         args.in_args[0].value = &inarg;
910         args.in_args[1].size = entry->d_name.l    780         args.in_args[1].size = entry->d_name.len + 1;
911         args.in_args[1].value = entry->d_name.    781         args.in_args[1].value = entry->d_name.name;
912         return create_new_entry(fm, &args, dir    782         return create_new_entry(fm, &args, dir, entry, S_IFDIR);
913 }                                                 783 }
914                                                   784 
915 static int fuse_symlink(struct mnt_idmap *idma !! 785 static int fuse_symlink(struct user_namespace *mnt_userns, struct inode *dir,
916                         struct dentry *entry,     786                         struct dentry *entry, const char *link)
917 {                                                 787 {
918         struct fuse_mount *fm = get_fuse_mount    788         struct fuse_mount *fm = get_fuse_mount(dir);
919         unsigned len = strlen(link) + 1;          789         unsigned len = strlen(link) + 1;
920         FUSE_ARGS(args);                          790         FUSE_ARGS(args);
921                                                   791 
922         args.opcode = FUSE_SYMLINK;               792         args.opcode = FUSE_SYMLINK;
923         args.in_numargs = 2;                      793         args.in_numargs = 2;
924         args.in_args[0].size = entry->d_name.l    794         args.in_args[0].size = entry->d_name.len + 1;
925         args.in_args[0].value = entry->d_name.    795         args.in_args[0].value = entry->d_name.name;
926         args.in_args[1].size = len;               796         args.in_args[1].size = len;
927         args.in_args[1].value = link;             797         args.in_args[1].value = link;
928         return create_new_entry(fm, &args, dir    798         return create_new_entry(fm, &args, dir, entry, S_IFLNK);
929 }                                                 799 }
930                                                   800 
931 void fuse_flush_time_update(struct inode *inod !! 801 void fuse_update_ctime(struct inode *inode)
932 {                                              << 
933         int err = sync_inode_metadata(inode, 1 << 
934                                                << 
935         mapping_set_error(inode->i_mapping, er << 
936 }                                              << 
937                                                << 
938 static void fuse_update_ctime_in_cache(struct  << 
939 {                                                 802 {
940         if (!IS_NOCMTIME(inode)) {                803         if (!IS_NOCMTIME(inode)) {
941                 inode_set_ctime_current(inode) !! 804                 inode->i_ctime = current_time(inode);
942                 mark_inode_dirty_sync(inode);     805                 mark_inode_dirty_sync(inode);
943                 fuse_flush_time_update(inode); << 
944         }                                         806         }
945 }                                                 807 }
946                                                   808 
947 void fuse_update_ctime(struct inode *inode)    << 
948 {                                              << 
949         fuse_invalidate_attr_mask(inode, STATX << 
950         fuse_update_ctime_in_cache(inode);     << 
951 }                                              << 
952                                                << 
953 static void fuse_entry_unlinked(struct dentry  << 
954 {                                              << 
955         struct inode *inode = d_inode(entry);  << 
956         struct fuse_conn *fc = get_fuse_conn(i << 
957         struct fuse_inode *fi = get_fuse_inode << 
958                                                << 
959         spin_lock(&fi->lock);                  << 
960         fi->attr_version = atomic64_inc_return << 
961         /*                                     << 
962          * If i_nlink == 0 then unlink doesn't << 
963          * happen if userspace filesystem is c << 
964          * difficult to enforce correct nlink  << 
965          * condition here                      << 
966          */                                    << 
967         if (S_ISDIR(inode->i_mode))            << 
968                 clear_nlink(inode);            << 
969         else if (inode->i_nlink > 0)           << 
970                 drop_nlink(inode);             << 
971         spin_unlock(&fi->lock);                << 
972         fuse_invalidate_entry_cache(entry);    << 
973         fuse_update_ctime(inode);              << 
974 }                                              << 
975                                                << 
976 static int fuse_unlink(struct inode *dir, stru    809 static int fuse_unlink(struct inode *dir, struct dentry *entry)
977 {                                                 810 {
978         int err;                                  811         int err;
979         struct fuse_mount *fm = get_fuse_mount    812         struct fuse_mount *fm = get_fuse_mount(dir);
980         FUSE_ARGS(args);                          813         FUSE_ARGS(args);
981                                                   814 
982         if (fuse_is_bad(dir))                     815         if (fuse_is_bad(dir))
983                 return -EIO;                      816                 return -EIO;
984                                                   817 
985         args.opcode = FUSE_UNLINK;                818         args.opcode = FUSE_UNLINK;
986         args.nodeid = get_node_id(dir);           819         args.nodeid = get_node_id(dir);
987         args.in_numargs = 1;                      820         args.in_numargs = 1;
988         args.in_args[0].size = entry->d_name.l    821         args.in_args[0].size = entry->d_name.len + 1;
989         args.in_args[0].value = entry->d_name.    822         args.in_args[0].value = entry->d_name.name;
990         err = fuse_simple_request(fm, &args);     823         err = fuse_simple_request(fm, &args);
991         if (!err) {                               824         if (!err) {
                                                   >> 825                 struct inode *inode = d_inode(entry);
                                                   >> 826                 struct fuse_inode *fi = get_fuse_inode(inode);
                                                   >> 827 
                                                   >> 828                 spin_lock(&fi->lock);
                                                   >> 829                 fi->attr_version = atomic64_inc_return(&fm->fc->attr_version);
                                                   >> 830                 /*
                                                   >> 831                  * If i_nlink == 0 then unlink doesn't make sense, yet this can
                                                   >> 832                  * happen if userspace filesystem is careless.  It would be
                                                   >> 833                  * difficult to enforce correct nlink usage so just ignore this
                                                   >> 834                  * condition here
                                                   >> 835                  */
                                                   >> 836                 if (inode->i_nlink > 0)
                                                   >> 837                         drop_nlink(inode);
                                                   >> 838                 spin_unlock(&fi->lock);
                                                   >> 839                 fuse_invalidate_attr(inode);
992                 fuse_dir_changed(dir);            840                 fuse_dir_changed(dir);
993                 fuse_entry_unlinked(entry);    !! 841                 fuse_invalidate_entry_cache(entry);
994         } else if (err == -EINTR || err == -EN !! 842                 fuse_update_ctime(inode);
                                                   >> 843         } else if (err == -EINTR)
995                 fuse_invalidate_entry(entry);     844                 fuse_invalidate_entry(entry);
996         return err;                               845         return err;
997 }                                                 846 }
998                                                   847 
999 static int fuse_rmdir(struct inode *dir, struc    848 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
1000 {                                                849 {
1001         int err;                                 850         int err;
1002         struct fuse_mount *fm = get_fuse_moun    851         struct fuse_mount *fm = get_fuse_mount(dir);
1003         FUSE_ARGS(args);                         852         FUSE_ARGS(args);
1004                                                  853 
1005         if (fuse_is_bad(dir))                    854         if (fuse_is_bad(dir))
1006                 return -EIO;                     855                 return -EIO;
1007                                                  856 
1008         args.opcode = FUSE_RMDIR;                857         args.opcode = FUSE_RMDIR;
1009         args.nodeid = get_node_id(dir);          858         args.nodeid = get_node_id(dir);
1010         args.in_numargs = 1;                     859         args.in_numargs = 1;
1011         args.in_args[0].size = entry->d_name.    860         args.in_args[0].size = entry->d_name.len + 1;
1012         args.in_args[0].value = entry->d_name    861         args.in_args[0].value = entry->d_name.name;
1013         err = fuse_simple_request(fm, &args);    862         err = fuse_simple_request(fm, &args);
1014         if (!err) {                              863         if (!err) {
                                                   >> 864                 clear_nlink(d_inode(entry));
1015                 fuse_dir_changed(dir);           865                 fuse_dir_changed(dir);
1016                 fuse_entry_unlinked(entry);   !! 866                 fuse_invalidate_entry_cache(entry);
1017         } else if (err == -EINTR || err == -E !! 867         } else if (err == -EINTR)
1018                 fuse_invalidate_entry(entry);    868                 fuse_invalidate_entry(entry);
1019         return err;                              869         return err;
1020 }                                                870 }
1021                                                  871 
1022 static int fuse_rename_common(struct inode *o    872 static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
1023                               struct inode *n    873                               struct inode *newdir, struct dentry *newent,
1024                               unsigned int fl    874                               unsigned int flags, int opcode, size_t argsize)
1025 {                                                875 {
1026         int err;                                 876         int err;
1027         struct fuse_rename2_in inarg;            877         struct fuse_rename2_in inarg;
1028         struct fuse_mount *fm = get_fuse_moun    878         struct fuse_mount *fm = get_fuse_mount(olddir);
1029         FUSE_ARGS(args);                         879         FUSE_ARGS(args);
1030                                                  880 
1031         memset(&inarg, 0, argsize);              881         memset(&inarg, 0, argsize);
1032         inarg.newdir = get_node_id(newdir);      882         inarg.newdir = get_node_id(newdir);
1033         inarg.flags = flags;                     883         inarg.flags = flags;
1034         args.opcode = opcode;                    884         args.opcode = opcode;
1035         args.nodeid = get_node_id(olddir);       885         args.nodeid = get_node_id(olddir);
1036         args.in_numargs = 3;                     886         args.in_numargs = 3;
1037         args.in_args[0].size = argsize;          887         args.in_args[0].size = argsize;
1038         args.in_args[0].value = &inarg;          888         args.in_args[0].value = &inarg;
1039         args.in_args[1].size = oldent->d_name    889         args.in_args[1].size = oldent->d_name.len + 1;
1040         args.in_args[1].value = oldent->d_nam    890         args.in_args[1].value = oldent->d_name.name;
1041         args.in_args[2].size = newent->d_name    891         args.in_args[2].size = newent->d_name.len + 1;
1042         args.in_args[2].value = newent->d_nam    892         args.in_args[2].value = newent->d_name.name;
1043         err = fuse_simple_request(fm, &args);    893         err = fuse_simple_request(fm, &args);
1044         if (!err) {                              894         if (!err) {
1045                 /* ctime changes */              895                 /* ctime changes */
                                                   >> 896                 fuse_invalidate_attr(d_inode(oldent));
1046                 fuse_update_ctime(d_inode(old    897                 fuse_update_ctime(d_inode(oldent));
1047                                                  898 
1048                 if (flags & RENAME_EXCHANGE)  !! 899                 if (flags & RENAME_EXCHANGE) {
                                                   >> 900                         fuse_invalidate_attr(d_inode(newent));
1049                         fuse_update_ctime(d_i    901                         fuse_update_ctime(d_inode(newent));
                                                   >> 902                 }
1050                                                  903 
1051                 fuse_dir_changed(olddir);        904                 fuse_dir_changed(olddir);
1052                 if (olddir != newdir)            905                 if (olddir != newdir)
1053                         fuse_dir_changed(newd    906                         fuse_dir_changed(newdir);
1054                                                  907 
1055                 /* newent will end up negativ    908                 /* newent will end up negative */
1056                 if (!(flags & RENAME_EXCHANGE !! 909                 if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) {
1057                         fuse_entry_unlinked(n !! 910                         fuse_invalidate_attr(d_inode(newent));
1058         } else if (err == -EINTR || err == -E !! 911                         fuse_invalidate_entry_cache(newent);
                                                   >> 912                         fuse_update_ctime(d_inode(newent));
                                                   >> 913                 }
                                                   >> 914         } else if (err == -EINTR) {
1059                 /* If request was interrupted    915                 /* If request was interrupted, DEITY only knows if the
1060                    rename actually took place    916                    rename actually took place.  If the invalidation
1061                    fails (e.g. some process h    917                    fails (e.g. some process has CWD under the renamed
1062                    directory), then there can    918                    directory), then there can be inconsistency between
1063                    the dcache and the real fi    919                    the dcache and the real filesystem.  Tough luck. */
1064                 fuse_invalidate_entry(oldent)    920                 fuse_invalidate_entry(oldent);
1065                 if (d_really_is_positive(newe    921                 if (d_really_is_positive(newent))
1066                         fuse_invalidate_entry    922                         fuse_invalidate_entry(newent);
1067         }                                        923         }
1068                                                  924 
1069         return err;                              925         return err;
1070 }                                                926 }
1071                                                  927 
1072 static int fuse_rename2(struct mnt_idmap *idm !! 928 static int fuse_rename2(struct user_namespace *mnt_userns, struct inode *olddir,
1073                         struct dentry *oldent    929                         struct dentry *oldent, struct inode *newdir,
1074                         struct dentry *newent    930                         struct dentry *newent, unsigned int flags)
1075 {                                                931 {
1076         struct fuse_conn *fc = get_fuse_conn(    932         struct fuse_conn *fc = get_fuse_conn(olddir);
1077         int err;                                 933         int err;
1078                                                  934 
1079         if (fuse_is_bad(olddir))                 935         if (fuse_is_bad(olddir))
1080                 return -EIO;                     936                 return -EIO;
1081                                                  937 
1082         if (flags & ~(RENAME_NOREPLACE | RENA    938         if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
1083                 return -EINVAL;                  939                 return -EINVAL;
1084                                                  940 
1085         if (flags) {                             941         if (flags) {
1086                 if (fc->no_rename2 || fc->min    942                 if (fc->no_rename2 || fc->minor < 23)
1087                         return -EINVAL;          943                         return -EINVAL;
1088                                                  944 
1089                 err = fuse_rename_common(oldd    945                 err = fuse_rename_common(olddir, oldent, newdir, newent, flags,
1090                                          FUSE    946                                          FUSE_RENAME2,
1091                                          size    947                                          sizeof(struct fuse_rename2_in));
1092                 if (err == -ENOSYS) {            948                 if (err == -ENOSYS) {
1093                         fc->no_rename2 = 1;      949                         fc->no_rename2 = 1;
1094                         err = -EINVAL;           950                         err = -EINVAL;
1095                 }                                951                 }
1096         } else {                                 952         } else {
1097                 err = fuse_rename_common(oldd    953                 err = fuse_rename_common(olddir, oldent, newdir, newent, 0,
1098                                          FUSE    954                                          FUSE_RENAME,
1099                                          size    955                                          sizeof(struct fuse_rename_in));
1100         }                                        956         }
1101                                                  957 
1102         return err;                              958         return err;
1103 }                                                959 }
1104                                                  960 
1105 static int fuse_link(struct dentry *entry, st    961 static int fuse_link(struct dentry *entry, struct inode *newdir,
1106                      struct dentry *newent)      962                      struct dentry *newent)
1107 {                                                963 {
1108         int err;                                 964         int err;
1109         struct fuse_link_in inarg;               965         struct fuse_link_in inarg;
1110         struct inode *inode = d_inode(entry);    966         struct inode *inode = d_inode(entry);
1111         struct fuse_mount *fm = get_fuse_moun    967         struct fuse_mount *fm = get_fuse_mount(inode);
1112         FUSE_ARGS(args);                         968         FUSE_ARGS(args);
1113                                                  969 
1114         memset(&inarg, 0, sizeof(inarg));        970         memset(&inarg, 0, sizeof(inarg));
1115         inarg.oldnodeid = get_node_id(inode);    971         inarg.oldnodeid = get_node_id(inode);
1116         args.opcode = FUSE_LINK;                 972         args.opcode = FUSE_LINK;
1117         args.in_numargs = 2;                     973         args.in_numargs = 2;
1118         args.in_args[0].size = sizeof(inarg);    974         args.in_args[0].size = sizeof(inarg);
1119         args.in_args[0].value = &inarg;          975         args.in_args[0].value = &inarg;
1120         args.in_args[1].size = newent->d_name    976         args.in_args[1].size = newent->d_name.len + 1;
1121         args.in_args[1].value = newent->d_nam    977         args.in_args[1].value = newent->d_name.name;
1122         err = create_new_entry(fm, &args, new    978         err = create_new_entry(fm, &args, newdir, newent, inode->i_mode);
1123         if (!err)                             !! 979         /* Contrary to "normal" filesystems it can happen that link
1124                 fuse_update_ctime_in_cache(in !! 980            makes two "logical" inodes point to the same "physical"
1125         else if (err == -EINTR)               !! 981            inode.  We invalidate the attributes of the old one, so it
1126                 fuse_invalidate_attr(inode);  !! 982            will reflect changes in the backing inode (link count,
                                                   >> 983            etc.)
                                                   >> 984         */
                                                   >> 985         if (!err) {
                                                   >> 986                 struct fuse_inode *fi = get_fuse_inode(inode);
1127                                                  987 
                                                   >> 988                 spin_lock(&fi->lock);
                                                   >> 989                 fi->attr_version = atomic64_inc_return(&fm->fc->attr_version);
                                                   >> 990                 if (likely(inode->i_nlink < UINT_MAX))
                                                   >> 991                         inc_nlink(inode);
                                                   >> 992                 spin_unlock(&fi->lock);
                                                   >> 993                 fuse_invalidate_attr(inode);
                                                   >> 994                 fuse_update_ctime(inode);
                                                   >> 995         } else if (err == -EINTR) {
                                                   >> 996                 fuse_invalidate_attr(inode);
                                                   >> 997         }
1128         return err;                              998         return err;
1129 }                                                999 }
1130                                                  1000 
1131 static void fuse_fillattr(struct inode *inode    1001 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
1132                           struct kstat *stat)    1002                           struct kstat *stat)
1133 {                                                1003 {
1134         unsigned int blkbits;                    1004         unsigned int blkbits;
1135         struct fuse_conn *fc = get_fuse_conn(    1005         struct fuse_conn *fc = get_fuse_conn(inode);
1136                                                  1006 
                                                   >> 1007         /* see the comment in fuse_change_attributes() */
                                                   >> 1008         if (fc->writeback_cache && S_ISREG(inode->i_mode)) {
                                                   >> 1009                 attr->size = i_size_read(inode);
                                                   >> 1010                 attr->mtime = inode->i_mtime.tv_sec;
                                                   >> 1011                 attr->mtimensec = inode->i_mtime.tv_nsec;
                                                   >> 1012                 attr->ctime = inode->i_ctime.tv_sec;
                                                   >> 1013                 attr->ctimensec = inode->i_ctime.tv_nsec;
                                                   >> 1014         }
                                                   >> 1015 
1137         stat->dev = inode->i_sb->s_dev;          1016         stat->dev = inode->i_sb->s_dev;
1138         stat->ino = attr->ino;                   1017         stat->ino = attr->ino;
1139         stat->mode = (inode->i_mode & S_IFMT)    1018         stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
1140         stat->nlink = attr->nlink;               1019         stat->nlink = attr->nlink;
1141         stat->uid = make_kuid(fc->user_ns, at    1020         stat->uid = make_kuid(fc->user_ns, attr->uid);
1142         stat->gid = make_kgid(fc->user_ns, at    1021         stat->gid = make_kgid(fc->user_ns, attr->gid);
1143         stat->rdev = inode->i_rdev;              1022         stat->rdev = inode->i_rdev;
1144         stat->atime.tv_sec = attr->atime;        1023         stat->atime.tv_sec = attr->atime;
1145         stat->atime.tv_nsec = attr->atimensec    1024         stat->atime.tv_nsec = attr->atimensec;
1146         stat->mtime.tv_sec = attr->mtime;        1025         stat->mtime.tv_sec = attr->mtime;
1147         stat->mtime.tv_nsec = attr->mtimensec    1026         stat->mtime.tv_nsec = attr->mtimensec;
1148         stat->ctime.tv_sec = attr->ctime;        1027         stat->ctime.tv_sec = attr->ctime;
1149         stat->ctime.tv_nsec = attr->ctimensec    1028         stat->ctime.tv_nsec = attr->ctimensec;
1150         stat->size = attr->size;                 1029         stat->size = attr->size;
1151         stat->blocks = attr->blocks;             1030         stat->blocks = attr->blocks;
1152                                                  1031 
1153         if (attr->blksize != 0)                  1032         if (attr->blksize != 0)
1154                 blkbits = ilog2(attr->blksize    1033                 blkbits = ilog2(attr->blksize);
1155         else                                     1034         else
1156                 blkbits = inode->i_sb->s_bloc    1035                 blkbits = inode->i_sb->s_blocksize_bits;
1157                                                  1036 
1158         stat->blksize = 1 << blkbits;            1037         stat->blksize = 1 << blkbits;
1159 }                                                1038 }
1160                                                  1039 
1161 static void fuse_statx_to_attr(struct fuse_st << 
1162 {                                             << 
1163         memset(attr, 0, sizeof(*attr));       << 
1164         attr->ino = sx->ino;                  << 
1165         attr->size = sx->size;                << 
1166         attr->blocks = sx->blocks;            << 
1167         attr->atime = sx->atime.tv_sec;       << 
1168         attr->mtime = sx->mtime.tv_sec;       << 
1169         attr->ctime = sx->ctime.tv_sec;       << 
1170         attr->atimensec = sx->atime.tv_nsec;  << 
1171         attr->mtimensec = sx->mtime.tv_nsec;  << 
1172         attr->ctimensec = sx->ctime.tv_nsec;  << 
1173         attr->mode = sx->mode;                << 
1174         attr->nlink = sx->nlink;              << 
1175         attr->uid = sx->uid;                  << 
1176         attr->gid = sx->gid;                  << 
1177         attr->rdev = new_encode_dev(MKDEV(sx- << 
1178         attr->blksize = sx->blksize;          << 
1179 }                                             << 
1180                                               << 
1181 static int fuse_do_statx(struct inode *inode, << 
1182                          struct kstat *stat)  << 
1183 {                                             << 
1184         int err;                              << 
1185         struct fuse_attr attr;                << 
1186         struct fuse_statx *sx;                << 
1187         struct fuse_statx_in inarg;           << 
1188         struct fuse_statx_out outarg;         << 
1189         struct fuse_mount *fm = get_fuse_moun << 
1190         u64 attr_version = fuse_get_attr_vers << 
1191         FUSE_ARGS(args);                      << 
1192                                               << 
1193         memset(&inarg, 0, sizeof(inarg));     << 
1194         memset(&outarg, 0, sizeof(outarg));   << 
1195         /* Directories have separate file-han << 
1196         if (file && S_ISREG(inode->i_mode)) { << 
1197                 struct fuse_file *ff = file-> << 
1198                                               << 
1199                 inarg.getattr_flags |= FUSE_G << 
1200                 inarg.fh = ff->fh;            << 
1201         }                                     << 
1202         /* For now leave sync hints as the de << 
1203         inarg.sx_flags = 0;                   << 
1204         inarg.sx_mask = STATX_BASIC_STATS | S << 
1205         args.opcode = FUSE_STATX;             << 
1206         args.nodeid = get_node_id(inode);     << 
1207         args.in_numargs = 1;                  << 
1208         args.in_args[0].size = sizeof(inarg); << 
1209         args.in_args[0].value = &inarg;       << 
1210         args.out_numargs = 1;                 << 
1211         args.out_args[0].size = sizeof(outarg << 
1212         args.out_args[0].value = &outarg;     << 
1213         err = fuse_simple_request(fm, &args); << 
1214         if (err)                              << 
1215                 return err;                   << 
1216                                               << 
1217         sx = &outarg.stat;                    << 
1218         if (((sx->mask & STATX_SIZE) && !fuse << 
1219             ((sx->mask & STATX_TYPE) && (!fus << 
1220                                          inod << 
1221                 fuse_make_bad(inode);         << 
1222                 return -EIO;                  << 
1223         }                                     << 
1224                                               << 
1225         fuse_statx_to_attr(&outarg.stat, &att << 
1226         if ((sx->mask & STATX_BASIC_STATS) == << 
1227                 fuse_change_attributes(inode, << 
1228                                        ATTR_T << 
1229         }                                     << 
1230                                               << 
1231         if (stat) {                           << 
1232                 stat->result_mask = sx->mask  << 
1233                 stat->btime.tv_sec = sx->btim << 
1234                 stat->btime.tv_nsec = min_t(u << 
1235                 fuse_fillattr(inode, &attr, s << 
1236                 stat->result_mask |= STATX_TY << 
1237         }                                     << 
1238                                               << 
1239         return 0;                             << 
1240 }                                             << 
1241                                               << 
1242 static int fuse_do_getattr(struct inode *inod    1040 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
1243                            struct file *file)    1041                            struct file *file)
1244 {                                                1042 {
1245         int err;                                 1043         int err;
1246         struct fuse_getattr_in inarg;            1044         struct fuse_getattr_in inarg;
1247         struct fuse_attr_out outarg;             1045         struct fuse_attr_out outarg;
1248         struct fuse_mount *fm = get_fuse_moun    1046         struct fuse_mount *fm = get_fuse_mount(inode);
1249         FUSE_ARGS(args);                         1047         FUSE_ARGS(args);
1250         u64 attr_version;                        1048         u64 attr_version;
1251                                                  1049 
1252         attr_version = fuse_get_attr_version(    1050         attr_version = fuse_get_attr_version(fm->fc);
1253                                                  1051 
1254         memset(&inarg, 0, sizeof(inarg));        1052         memset(&inarg, 0, sizeof(inarg));
1255         memset(&outarg, 0, sizeof(outarg));      1053         memset(&outarg, 0, sizeof(outarg));
1256         /* Directories have separate file-han    1054         /* Directories have separate file-handle space */
1257         if (file && S_ISREG(inode->i_mode)) {    1055         if (file && S_ISREG(inode->i_mode)) {
1258                 struct fuse_file *ff = file->    1056                 struct fuse_file *ff = file->private_data;
1259                                                  1057 
1260                 inarg.getattr_flags |= FUSE_G    1058                 inarg.getattr_flags |= FUSE_GETATTR_FH;
1261                 inarg.fh = ff->fh;               1059                 inarg.fh = ff->fh;
1262         }                                        1060         }
1263         args.opcode = FUSE_GETATTR;              1061         args.opcode = FUSE_GETATTR;
1264         args.nodeid = get_node_id(inode);        1062         args.nodeid = get_node_id(inode);
1265         args.in_numargs = 1;                     1063         args.in_numargs = 1;
1266         args.in_args[0].size = sizeof(inarg);    1064         args.in_args[0].size = sizeof(inarg);
1267         args.in_args[0].value = &inarg;          1065         args.in_args[0].value = &inarg;
1268         args.out_numargs = 1;                    1066         args.out_numargs = 1;
1269         args.out_args[0].size = sizeof(outarg    1067         args.out_args[0].size = sizeof(outarg);
1270         args.out_args[0].value = &outarg;        1068         args.out_args[0].value = &outarg;
1271         err = fuse_simple_request(fm, &args);    1069         err = fuse_simple_request(fm, &args);
1272         if (!err) {                              1070         if (!err) {
1273                 if (fuse_invalid_attr(&outarg    1071                 if (fuse_invalid_attr(&outarg.attr) ||
1274                     inode_wrong_type(inode, o !! 1072                     (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1275                         fuse_make_bad(inode);    1073                         fuse_make_bad(inode);
1276                         err = -EIO;              1074                         err = -EIO;
1277                 } else {                         1075                 } else {
1278                         fuse_change_attribute !! 1076                         fuse_change_attributes(inode, &outarg.attr,
1279                                               !! 1077                                                attr_timeout(&outarg),
1280                                                  1078                                                attr_version);
1281                         if (stat)                1079                         if (stat)
1282                                 fuse_fillattr    1080                                 fuse_fillattr(inode, &outarg.attr, stat);
1283                 }                                1081                 }
1284         }                                        1082         }
1285         return err;                              1083         return err;
1286 }                                                1084 }
1287                                                  1085 
1288 static int fuse_update_get_attr(struct inode     1086 static int fuse_update_get_attr(struct inode *inode, struct file *file,
1289                                 struct kstat     1087                                 struct kstat *stat, u32 request_mask,
1290                                 unsigned int     1088                                 unsigned int flags)
1291 {                                                1089 {
1292         struct fuse_inode *fi = get_fuse_inod    1090         struct fuse_inode *fi = get_fuse_inode(inode);
1293         struct fuse_conn *fc = get_fuse_conn( << 
1294         int err = 0;                             1091         int err = 0;
1295         bool sync;                               1092         bool sync;
1296         u32 inval_mask = READ_ONCE(fi->inval_ << 
1297         u32 cache_mask = fuse_get_cache_mask( << 
1298                                               << 
1299                                               << 
1300         /* FUSE only supports basic stats and << 
1301         request_mask &= STATX_BASIC_STATS | S << 
1302 retry:                                        << 
1303         if (fc->no_statx)                     << 
1304                 request_mask &= STATX_BASIC_S << 
1305                                                  1093 
1306         if (!request_mask)                    !! 1094         if (flags & AT_STATX_FORCE_SYNC)
1307                 sync = false;                 << 
1308         else if (flags & AT_STATX_FORCE_SYNC) << 
1309                 sync = true;                     1095                 sync = true;
1310         else if (flags & AT_STATX_DONT_SYNC)     1096         else if (flags & AT_STATX_DONT_SYNC)
1311                 sync = false;                    1097                 sync = false;
1312         else if (request_mask & inval_mask &  !! 1098         else if (request_mask & READ_ONCE(fi->inval_mask))
1313                 sync = true;                     1099                 sync = true;
1314         else                                     1100         else
1315                 sync = time_before64(fi->i_ti    1101                 sync = time_before64(fi->i_time, get_jiffies_64());
1316                                                  1102 
1317         if (sync) {                              1103         if (sync) {
1318                 forget_all_cached_acls(inode)    1104                 forget_all_cached_acls(inode);
1319                 /* Try statx if BTIME is requ !! 1105                 err = fuse_do_getattr(inode, stat, file);
1320                 if (!fc->no_statx && (request << 
1321                         err = fuse_do_statx(i << 
1322                         if (err == -ENOSYS) { << 
1323                                 fc->no_statx  << 
1324                                 err = 0;      << 
1325                                 goto retry;   << 
1326                         }                     << 
1327                 } else {                      << 
1328                         err = fuse_do_getattr << 
1329                 }                             << 
1330         } else if (stat) {                       1106         } else if (stat) {
1331                 generic_fillattr(&nop_mnt_idm !! 1107                 generic_fillattr(&init_user_ns, inode, stat);
1332                 stat->mode = fi->orig_i_mode;    1108                 stat->mode = fi->orig_i_mode;
1333                 stat->ino = fi->orig_ino;        1109                 stat->ino = fi->orig_ino;
1334                 if (test_bit(FUSE_I_BTIME, &f << 
1335                         stat->btime = fi->i_b << 
1336                         stat->result_mask |=  << 
1337                 }                             << 
1338         }                                        1110         }
1339                                                  1111 
1340         return err;                              1112         return err;
1341 }                                                1113 }
1342                                                  1114 
1343 int fuse_update_attributes(struct inode *inod !! 1115 int fuse_update_attributes(struct inode *inode, struct file *file)
1344 {                                                1116 {
1345         return fuse_update_get_attr(inode, fi !! 1117         /* Do *not* need to get atime for internal purposes */
                                                   >> 1118         return fuse_update_get_attr(inode, file, NULL,
                                                   >> 1119                                     STATX_BASIC_STATS & ~STATX_ATIME, 0);
1346 }                                                1120 }
1347                                                  1121 
1348 int fuse_reverse_inval_entry(struct fuse_conn    1122 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
1349                              u64 child_nodeid !! 1123                              u64 child_nodeid, struct qstr *name)
1350 {                                                1124 {
1351         int err = -ENOTDIR;                      1125         int err = -ENOTDIR;
1352         struct inode *parent;                    1126         struct inode *parent;
1353         struct dentry *dir;                      1127         struct dentry *dir;
1354         struct dentry *entry;                    1128         struct dentry *entry;
1355                                                  1129 
1356         parent = fuse_ilookup(fc, parent_node    1130         parent = fuse_ilookup(fc, parent_nodeid, NULL);
1357         if (!parent)                             1131         if (!parent)
1358                 return -ENOENT;                  1132                 return -ENOENT;
1359                                                  1133 
1360         inode_lock_nested(parent, I_MUTEX_PAR !! 1134         inode_lock(parent);
1361         if (!S_ISDIR(parent->i_mode))            1135         if (!S_ISDIR(parent->i_mode))
1362                 goto unlock;                     1136                 goto unlock;
1363                                                  1137 
1364         err = -ENOENT;                           1138         err = -ENOENT;
1365         dir = d_find_alias(parent);              1139         dir = d_find_alias(parent);
1366         if (!dir)                                1140         if (!dir)
1367                 goto unlock;                     1141                 goto unlock;
1368                                                  1142 
1369         name->hash = full_name_hash(dir, name    1143         name->hash = full_name_hash(dir, name->name, name->len);
1370         entry = d_lookup(dir, name);             1144         entry = d_lookup(dir, name);
1371         dput(dir);                               1145         dput(dir);
1372         if (!entry)                              1146         if (!entry)
1373                 goto unlock;                     1147                 goto unlock;
1374                                                  1148 
1375         fuse_dir_changed(parent);                1149         fuse_dir_changed(parent);
1376         if (!(flags & FUSE_EXPIRE_ONLY))      !! 1150         fuse_invalidate_entry(entry);
1377                 d_invalidate(entry);          << 
1378         fuse_invalidate_entry_cache(entry);   << 
1379                                                  1151 
1380         if (child_nodeid != 0 && d_really_is_    1152         if (child_nodeid != 0 && d_really_is_positive(entry)) {
1381                 inode_lock(d_inode(entry));      1153                 inode_lock(d_inode(entry));
1382                 if (get_node_id(d_inode(entry    1154                 if (get_node_id(d_inode(entry)) != child_nodeid) {
1383                         err = -ENOENT;           1155                         err = -ENOENT;
1384                         goto badentry;           1156                         goto badentry;
1385                 }                                1157                 }
1386                 if (d_mountpoint(entry)) {       1158                 if (d_mountpoint(entry)) {
1387                         err = -EBUSY;            1159                         err = -EBUSY;
1388                         goto badentry;           1160                         goto badentry;
1389                 }                                1161                 }
1390                 if (d_is_dir(entry)) {           1162                 if (d_is_dir(entry)) {
1391                         shrink_dcache_parent(    1163                         shrink_dcache_parent(entry);
1392                         if (!simple_empty(ent    1164                         if (!simple_empty(entry)) {
1393                                 err = -ENOTEM    1165                                 err = -ENOTEMPTY;
1394                                 goto badentry    1166                                 goto badentry;
1395                         }                        1167                         }
1396                         d_inode(entry)->i_fla    1168                         d_inode(entry)->i_flags |= S_DEAD;
1397                 }                                1169                 }
1398                 dont_mount(entry);               1170                 dont_mount(entry);
1399                 clear_nlink(d_inode(entry));     1171                 clear_nlink(d_inode(entry));
1400                 err = 0;                         1172                 err = 0;
1401  badentry:                                       1173  badentry:
1402                 inode_unlock(d_inode(entry));    1174                 inode_unlock(d_inode(entry));
1403                 if (!err)                        1175                 if (!err)
1404                         d_delete(entry);         1176                         d_delete(entry);
1405         } else {                                 1177         } else {
1406                 err = 0;                         1178                 err = 0;
1407         }                                        1179         }
1408         dput(entry);                             1180         dput(entry);
1409                                                  1181 
1410  unlock:                                         1182  unlock:
1411         inode_unlock(parent);                    1183         inode_unlock(parent);
1412         iput(parent);                            1184         iput(parent);
1413         return err;                              1185         return err;
1414 }                                                1186 }
1415                                                  1187 
1416 static inline bool fuse_permissible_uidgid(st << 
1417 {                                             << 
1418         const struct cred *cred = current_cre << 
1419                                               << 
1420         return (uid_eq(cred->euid, fc->user_i << 
1421                 uid_eq(cred->suid, fc->user_i << 
1422                 uid_eq(cred->uid,  fc->user_i << 
1423                 gid_eq(cred->egid, fc->group_ << 
1424                 gid_eq(cred->sgid, fc->group_ << 
1425                 gid_eq(cred->gid,  fc->group_ << 
1426 }                                             << 
1427                                               << 
1428 /*                                               1188 /*
1429  * Calling into a user-controlled filesystem     1189  * Calling into a user-controlled filesystem gives the filesystem
1430  * daemon ptrace-like capabilities over the c    1190  * daemon ptrace-like capabilities over the current process.  This
1431  * means, that the filesystem daemon is able     1191  * means, that the filesystem daemon is able to record the exact
1432  * filesystem operations performed, and can a    1192  * filesystem operations performed, and can also control the behavior
1433  * of the requester process in otherwise impo    1193  * of the requester process in otherwise impossible ways.  For example
1434  * it can delay the operation for arbitrary l    1194  * it can delay the operation for arbitrary length of time allowing
1435  * DoS against the requester.                    1195  * DoS against the requester.
1436  *                                               1196  *
1437  * For this reason only those processes can c    1197  * For this reason only those processes can call into the filesystem,
1438  * for which the owner of the mount has ptrac    1198  * for which the owner of the mount has ptrace privilege.  This
1439  * excludes processes started by other users,    1199  * excludes processes started by other users, suid or sgid processes.
1440  */                                              1200  */
1441 bool fuse_allow_current_process(struct fuse_c !! 1201 int fuse_allow_current_process(struct fuse_conn *fc)
1442 {                                                1202 {
1443         bool allow;                           !! 1203         const struct cred *cred;
1444                                                  1204 
1445         if (fc->allow_other)                     1205         if (fc->allow_other)
1446                 allow = current_in_userns(fc- !! 1206                 return current_in_userns(fc->user_ns);
1447         else                                  << 
1448                 allow = fuse_permissible_uidg << 
1449                                                  1207 
1450         if (!allow && allow_sys_admin_access  !! 1208         cred = current_cred();
1451                 allow = true;                 !! 1209         if (uid_eq(cred->euid, fc->user_id) &&
                                                   >> 1210             uid_eq(cred->suid, fc->user_id) &&
                                                   >> 1211             uid_eq(cred->uid,  fc->user_id) &&
                                                   >> 1212             gid_eq(cred->egid, fc->group_id) &&
                                                   >> 1213             gid_eq(cred->sgid, fc->group_id) &&
                                                   >> 1214             gid_eq(cred->gid,  fc->group_id))
                                                   >> 1215                 return 1;
1452                                                  1216 
1453         return allow;                         !! 1217         return 0;
1454 }                                                1218 }
1455                                                  1219 
1456 static int fuse_access(struct inode *inode, i    1220 static int fuse_access(struct inode *inode, int mask)
1457 {                                                1221 {
1458         struct fuse_mount *fm = get_fuse_moun    1222         struct fuse_mount *fm = get_fuse_mount(inode);
1459         FUSE_ARGS(args);                         1223         FUSE_ARGS(args);
1460         struct fuse_access_in inarg;             1224         struct fuse_access_in inarg;
1461         int err;                                 1225         int err;
1462                                                  1226 
1463         BUG_ON(mask & MAY_NOT_BLOCK);            1227         BUG_ON(mask & MAY_NOT_BLOCK);
1464                                                  1228 
1465         if (fm->fc->no_access)                   1229         if (fm->fc->no_access)
1466                 return 0;                        1230                 return 0;
1467                                                  1231 
1468         memset(&inarg, 0, sizeof(inarg));        1232         memset(&inarg, 0, sizeof(inarg));
1469         inarg.mask = mask & (MAY_READ | MAY_W    1233         inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1470         args.opcode = FUSE_ACCESS;               1234         args.opcode = FUSE_ACCESS;
1471         args.nodeid = get_node_id(inode);        1235         args.nodeid = get_node_id(inode);
1472         args.in_numargs = 1;                     1236         args.in_numargs = 1;
1473         args.in_args[0].size = sizeof(inarg);    1237         args.in_args[0].size = sizeof(inarg);
1474         args.in_args[0].value = &inarg;          1238         args.in_args[0].value = &inarg;
1475         err = fuse_simple_request(fm, &args);    1239         err = fuse_simple_request(fm, &args);
1476         if (err == -ENOSYS) {                    1240         if (err == -ENOSYS) {
1477                 fm->fc->no_access = 1;           1241                 fm->fc->no_access = 1;
1478                 err = 0;                         1242                 err = 0;
1479         }                                        1243         }
1480         return err;                              1244         return err;
1481 }                                                1245 }
1482                                                  1246 
1483 static int fuse_perm_getattr(struct inode *in    1247 static int fuse_perm_getattr(struct inode *inode, int mask)
1484 {                                                1248 {
1485         if (mask & MAY_NOT_BLOCK)                1249         if (mask & MAY_NOT_BLOCK)
1486                 return -ECHILD;                  1250                 return -ECHILD;
1487                                                  1251 
1488         forget_all_cached_acls(inode);           1252         forget_all_cached_acls(inode);
1489         return fuse_do_getattr(inode, NULL, N    1253         return fuse_do_getattr(inode, NULL, NULL);
1490 }                                                1254 }
1491                                                  1255 
1492 /*                                               1256 /*
1493  * Check permission.  The two basic access mo    1257  * Check permission.  The two basic access models of FUSE are:
1494  *                                               1258  *
1495  * 1) Local access checking ('default_permiss    1259  * 1) Local access checking ('default_permissions' mount option) based
1496  * on file mode.  This is the plain old disk     1260  * on file mode.  This is the plain old disk filesystem permission
1497  * model.                                     !! 1261  * modell.
1498  *                                               1262  *
1499  * 2) "Remote" access checking, where server     1263  * 2) "Remote" access checking, where server is responsible for
1500  * checking permission in each inode operatio    1264  * checking permission in each inode operation.  An exception to this
1501  * is if ->permission() was invoked from sys_    1265  * is if ->permission() was invoked from sys_access() in which case an
1502  * access request is sent.  Execute permissio    1266  * access request is sent.  Execute permission is still checked
1503  * locally based on file mode.                   1267  * locally based on file mode.
1504  */                                              1268  */
1505 static int fuse_permission(struct mnt_idmap * !! 1269 static int fuse_permission(struct user_namespace *mnt_userns,
1506                            struct inode *inod    1270                            struct inode *inode, int mask)
1507 {                                                1271 {
1508         struct fuse_conn *fc = get_fuse_conn(    1272         struct fuse_conn *fc = get_fuse_conn(inode);
1509         bool refreshed = false;                  1273         bool refreshed = false;
1510         int err = 0;                             1274         int err = 0;
1511                                                  1275 
1512         if (fuse_is_bad(inode))                  1276         if (fuse_is_bad(inode))
1513                 return -EIO;                     1277                 return -EIO;
1514                                                  1278 
1515         if (!fuse_allow_current_process(fc))     1279         if (!fuse_allow_current_process(fc))
1516                 return -EACCES;                  1280                 return -EACCES;
1517                                                  1281 
1518         /*                                       1282         /*
1519          * If attributes are needed, refresh     1283          * If attributes are needed, refresh them before proceeding
1520          */                                      1284          */
1521         if (fc->default_permissions ||           1285         if (fc->default_permissions ||
1522             ((mask & MAY_EXEC) && S_ISREG(ino    1286             ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1523                 struct fuse_inode *fi = get_f    1287                 struct fuse_inode *fi = get_fuse_inode(inode);
1524                 u32 perm_mask = STATX_MODE |     1288                 u32 perm_mask = STATX_MODE | STATX_UID | STATX_GID;
1525                                                  1289 
1526                 if (perm_mask & READ_ONCE(fi-    1290                 if (perm_mask & READ_ONCE(fi->inval_mask) ||
1527                     time_before64(fi->i_time,    1291                     time_before64(fi->i_time, get_jiffies_64())) {
1528                         refreshed = true;        1292                         refreshed = true;
1529                                                  1293 
1530                         err = fuse_perm_getat    1294                         err = fuse_perm_getattr(inode, mask);
1531                         if (err)                 1295                         if (err)
1532                                 return err;      1296                                 return err;
1533                 }                                1297                 }
1534         }                                        1298         }
1535                                                  1299 
1536         if (fc->default_permissions) {           1300         if (fc->default_permissions) {
1537                 err = generic_permission(&nop !! 1301                 err = generic_permission(&init_user_ns, inode, mask);
1538                                                  1302 
1539                 /* If permission is denied, t    1303                 /* If permission is denied, try to refresh file
1540                    attributes.  This is also     1304                    attributes.  This is also needed, because the root
1541                    node will at first have no    1305                    node will at first have no permissions */
1542                 if (err == -EACCES && !refres    1306                 if (err == -EACCES && !refreshed) {
1543                         err = fuse_perm_getat    1307                         err = fuse_perm_getattr(inode, mask);
1544                         if (!err)                1308                         if (!err)
1545                                 err = generic !! 1309                                 err = generic_permission(&init_user_ns,
1546                                                  1310                                                          inode, mask);
1547                 }                                1311                 }
1548                                                  1312 
1549                 /* Note: the opposite of the     1313                 /* Note: the opposite of the above test does not
1550                    exist.  So if permissions     1314                    exist.  So if permissions are revoked this won't be
1551                    noticed immediately, only     1315                    noticed immediately, only after the attribute
1552                    timeout has expired */        1316                    timeout has expired */
1553         } else if (mask & (MAY_ACCESS | MAY_C    1317         } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1554                 err = fuse_access(inode, mask    1318                 err = fuse_access(inode, mask);
1555         } else if ((mask & MAY_EXEC) && S_ISR    1319         } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1556                 if (!(inode->i_mode & S_IXUGO    1320                 if (!(inode->i_mode & S_IXUGO)) {
1557                         if (refreshed)           1321                         if (refreshed)
1558                                 return -EACCE    1322                                 return -EACCES;
1559                                                  1323 
1560                         err = fuse_perm_getat    1324                         err = fuse_perm_getattr(inode, mask);
1561                         if (!err && !(inode->    1325                         if (!err && !(inode->i_mode & S_IXUGO))
1562                                 return -EACCE    1326                                 return -EACCES;
1563                 }                                1327                 }
1564         }                                        1328         }
1565         return err;                              1329         return err;
1566 }                                                1330 }
1567                                                  1331 
1568 static int fuse_readlink_page(struct inode *i    1332 static int fuse_readlink_page(struct inode *inode, struct page *page)
1569 {                                                1333 {
1570         struct fuse_mount *fm = get_fuse_moun    1334         struct fuse_mount *fm = get_fuse_mount(inode);
1571         struct fuse_page_desc desc = { .lengt    1335         struct fuse_page_desc desc = { .length = PAGE_SIZE - 1 };
1572         struct fuse_args_pages ap = {            1336         struct fuse_args_pages ap = {
1573                 .num_pages = 1,                  1337                 .num_pages = 1,
1574                 .pages = &page,                  1338                 .pages = &page,
1575                 .descs = &desc,                  1339                 .descs = &desc,
1576         };                                       1340         };
1577         char *link;                              1341         char *link;
1578         ssize_t res;                             1342         ssize_t res;
1579                                                  1343 
1580         ap.args.opcode = FUSE_READLINK;          1344         ap.args.opcode = FUSE_READLINK;
1581         ap.args.nodeid = get_node_id(inode);     1345         ap.args.nodeid = get_node_id(inode);
1582         ap.args.out_pages = true;                1346         ap.args.out_pages = true;
1583         ap.args.out_argvar = true;               1347         ap.args.out_argvar = true;
1584         ap.args.page_zeroing = true;             1348         ap.args.page_zeroing = true;
1585         ap.args.out_numargs = 1;                 1349         ap.args.out_numargs = 1;
1586         ap.args.out_args[0].size = desc.lengt    1350         ap.args.out_args[0].size = desc.length;
1587         res = fuse_simple_request(fm, &ap.arg    1351         res = fuse_simple_request(fm, &ap.args);
1588                                                  1352 
1589         fuse_invalidate_atime(inode);            1353         fuse_invalidate_atime(inode);
1590                                                  1354 
1591         if (res < 0)                             1355         if (res < 0)
1592                 return res;                      1356                 return res;
1593                                                  1357 
1594         if (WARN_ON(res >= PAGE_SIZE))           1358         if (WARN_ON(res >= PAGE_SIZE))
1595                 return -EIO;                     1359                 return -EIO;
1596                                                  1360 
1597         link = page_address(page);               1361         link = page_address(page);
1598         link[res] = '\0';                        1362         link[res] = '\0';
1599                                                  1363 
1600         return 0;                                1364         return 0;
1601 }                                                1365 }
1602                                                  1366 
1603 static const char *fuse_get_link(struct dentr    1367 static const char *fuse_get_link(struct dentry *dentry, struct inode *inode,
1604                                  struct delay    1368                                  struct delayed_call *callback)
1605 {                                                1369 {
1606         struct fuse_conn *fc = get_fuse_conn(    1370         struct fuse_conn *fc = get_fuse_conn(inode);
1607         struct page *page;                       1371         struct page *page;
1608         int err;                                 1372         int err;
1609                                                  1373 
1610         err = -EIO;                              1374         err = -EIO;
1611         if (fuse_is_bad(inode))                  1375         if (fuse_is_bad(inode))
1612                 goto out_err;                    1376                 goto out_err;
1613                                                  1377 
1614         if (fc->cache_symlinks)                  1378         if (fc->cache_symlinks)
1615                 return page_get_link(dentry,     1379                 return page_get_link(dentry, inode, callback);
1616                                                  1380 
1617         err = -ECHILD;                           1381         err = -ECHILD;
1618         if (!dentry)                             1382         if (!dentry)
1619                 goto out_err;                    1383                 goto out_err;
1620                                                  1384 
1621         page = alloc_page(GFP_KERNEL);           1385         page = alloc_page(GFP_KERNEL);
1622         err = -ENOMEM;                           1386         err = -ENOMEM;
1623         if (!page)                               1387         if (!page)
1624                 goto out_err;                    1388                 goto out_err;
1625                                                  1389 
1626         err = fuse_readlink_page(inode, page)    1390         err = fuse_readlink_page(inode, page);
1627         if (err) {                               1391         if (err) {
1628                 __free_page(page);               1392                 __free_page(page);
1629                 goto out_err;                    1393                 goto out_err;
1630         }                                        1394         }
1631                                                  1395 
1632         set_delayed_call(callback, page_put_l    1396         set_delayed_call(callback, page_put_link, page);
1633                                                  1397 
1634         return page_address(page);               1398         return page_address(page);
1635                                                  1399 
1636 out_err:                                         1400 out_err:
1637         return ERR_PTR(err);                     1401         return ERR_PTR(err);
1638 }                                                1402 }
1639                                                  1403 
1640 static int fuse_dir_open(struct inode *inode,    1404 static int fuse_dir_open(struct inode *inode, struct file *file)
1641 {                                                1405 {
1642         struct fuse_mount *fm = get_fuse_moun !! 1406         return fuse_open_common(inode, file, true);
1643         int err;                              << 
1644                                               << 
1645         if (fuse_is_bad(inode))               << 
1646                 return -EIO;                  << 
1647                                               << 
1648         err = generic_file_open(inode, file); << 
1649         if (err)                              << 
1650                 return err;                   << 
1651                                               << 
1652         err = fuse_do_open(fm, get_node_id(in << 
1653         if (!err) {                           << 
1654                 struct fuse_file *ff = file-> << 
1655                                               << 
1656                 /*                            << 
1657                  * Keep handling FOPEN_STREAM << 
1658                  * directories for backward c << 
1659                  * to be useful.              << 
1660                  */                           << 
1661                 if (ff->open_flags & (FOPEN_S << 
1662                         nonseekable_open(inod << 
1663         }                                     << 
1664                                               << 
1665         return err;                           << 
1666 }                                                1407 }
1667                                                  1408 
1668 static int fuse_dir_release(struct inode *ino    1409 static int fuse_dir_release(struct inode *inode, struct file *file)
1669 {                                                1410 {
1670         fuse_release_common(file, true);         1411         fuse_release_common(file, true);
1671                                                  1412 
1672         return 0;                                1413         return 0;
1673 }                                                1414 }
1674                                                  1415 
1675 static int fuse_dir_fsync(struct file *file,     1416 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1676                           int datasync)          1417                           int datasync)
1677 {                                                1418 {
1678         struct inode *inode = file->f_mapping    1419         struct inode *inode = file->f_mapping->host;
1679         struct fuse_conn *fc = get_fuse_conn(    1420         struct fuse_conn *fc = get_fuse_conn(inode);
1680         int err;                                 1421         int err;
1681                                                  1422 
1682         if (fuse_is_bad(inode))                  1423         if (fuse_is_bad(inode))
1683                 return -EIO;                     1424                 return -EIO;
1684                                                  1425 
1685         if (fc->no_fsyncdir)                     1426         if (fc->no_fsyncdir)
1686                 return 0;                        1427                 return 0;
1687                                                  1428 
1688         inode_lock(inode);                       1429         inode_lock(inode);
1689         err = fuse_fsync_common(file, start,     1430         err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNCDIR);
1690         if (err == -ENOSYS) {                    1431         if (err == -ENOSYS) {
1691                 fc->no_fsyncdir = 1;             1432                 fc->no_fsyncdir = 1;
1692                 err = 0;                         1433                 err = 0;
1693         }                                        1434         }
1694         inode_unlock(inode);                     1435         inode_unlock(inode);
1695                                                  1436 
1696         return err;                              1437         return err;
1697 }                                                1438 }
1698                                                  1439 
1699 static long fuse_dir_ioctl(struct file *file,    1440 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1700                             unsigned long arg    1441                             unsigned long arg)
1701 {                                                1442 {
1702         struct fuse_conn *fc = get_fuse_conn(    1443         struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1703                                                  1444 
1704         /* FUSE_IOCTL_DIR only supported for     1445         /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1705         if (fc->minor < 18)                      1446         if (fc->minor < 18)
1706                 return -ENOTTY;                  1447                 return -ENOTTY;
1707                                                  1448 
1708         return fuse_ioctl_common(file, cmd, a    1449         return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1709 }                                                1450 }
1710                                                  1451 
1711 static long fuse_dir_compat_ioctl(struct file    1452 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1712                                    unsigned l    1453                                    unsigned long arg)
1713 {                                                1454 {
1714         struct fuse_conn *fc = get_fuse_conn(    1455         struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1715                                                  1456 
1716         if (fc->minor < 18)                      1457         if (fc->minor < 18)
1717                 return -ENOTTY;                  1458                 return -ENOTTY;
1718                                                  1459 
1719         return fuse_ioctl_common(file, cmd, a    1460         return fuse_ioctl_common(file, cmd, arg,
1720                                  FUSE_IOCTL_C    1461                                  FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1721 }                                                1462 }
1722                                                  1463 
1723 static bool update_mtime(unsigned ivalid, boo    1464 static bool update_mtime(unsigned ivalid, bool trust_local_mtime)
1724 {                                                1465 {
1725         /* Always update if mtime is explicit    1466         /* Always update if mtime is explicitly set  */
1726         if (ivalid & ATTR_MTIME_SET)             1467         if (ivalid & ATTR_MTIME_SET)
1727                 return true;                     1468                 return true;
1728                                                  1469 
1729         /* Or if kernel i_mtime is the offici    1470         /* Or if kernel i_mtime is the official one */
1730         if (trust_local_mtime)                   1471         if (trust_local_mtime)
1731                 return true;                     1472                 return true;
1732                                                  1473 
1733         /* If it's an open(O_TRUNC) or an ftr    1474         /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1734         if ((ivalid & ATTR_SIZE) && (ivalid &    1475         if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1735                 return false;                    1476                 return false;
1736                                                  1477 
1737         /* In all other cases update */          1478         /* In all other cases update */
1738         return true;                             1479         return true;
1739 }                                                1480 }
1740                                                  1481 
1741 static void iattr_to_fattr(struct fuse_conn *    1482 static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr,
1742                            struct fuse_setatt    1483                            struct fuse_setattr_in *arg, bool trust_local_cmtime)
1743 {                                                1484 {
1744         unsigned ivalid = iattr->ia_valid;       1485         unsigned ivalid = iattr->ia_valid;
1745                                                  1486 
1746         if (ivalid & ATTR_MODE)                  1487         if (ivalid & ATTR_MODE)
1747                 arg->valid |= FATTR_MODE,   a    1488                 arg->valid |= FATTR_MODE,   arg->mode = iattr->ia_mode;
1748         if (ivalid & ATTR_UID)                   1489         if (ivalid & ATTR_UID)
1749                 arg->valid |= FATTR_UID,    a    1490                 arg->valid |= FATTR_UID,    arg->uid = from_kuid(fc->user_ns, iattr->ia_uid);
1750         if (ivalid & ATTR_GID)                   1491         if (ivalid & ATTR_GID)
1751                 arg->valid |= FATTR_GID,    a    1492                 arg->valid |= FATTR_GID,    arg->gid = from_kgid(fc->user_ns, iattr->ia_gid);
1752         if (ivalid & ATTR_SIZE)                  1493         if (ivalid & ATTR_SIZE)
1753                 arg->valid |= FATTR_SIZE,   a    1494                 arg->valid |= FATTR_SIZE,   arg->size = iattr->ia_size;
1754         if (ivalid & ATTR_ATIME) {               1495         if (ivalid & ATTR_ATIME) {
1755                 arg->valid |= FATTR_ATIME;       1496                 arg->valid |= FATTR_ATIME;
1756                 arg->atime = iattr->ia_atime.    1497                 arg->atime = iattr->ia_atime.tv_sec;
1757                 arg->atimensec = iattr->ia_at    1498                 arg->atimensec = iattr->ia_atime.tv_nsec;
1758                 if (!(ivalid & ATTR_ATIME_SET    1499                 if (!(ivalid & ATTR_ATIME_SET))
1759                         arg->valid |= FATTR_A    1500                         arg->valid |= FATTR_ATIME_NOW;
1760         }                                        1501         }
1761         if ((ivalid & ATTR_MTIME) && update_m    1502         if ((ivalid & ATTR_MTIME) && update_mtime(ivalid, trust_local_cmtime)) {
1762                 arg->valid |= FATTR_MTIME;       1503                 arg->valid |= FATTR_MTIME;
1763                 arg->mtime = iattr->ia_mtime.    1504                 arg->mtime = iattr->ia_mtime.tv_sec;
1764                 arg->mtimensec = iattr->ia_mt    1505                 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1765                 if (!(ivalid & ATTR_MTIME_SET    1506                 if (!(ivalid & ATTR_MTIME_SET) && !trust_local_cmtime)
1766                         arg->valid |= FATTR_M    1507                         arg->valid |= FATTR_MTIME_NOW;
1767         }                                        1508         }
1768         if ((ivalid & ATTR_CTIME) && trust_lo    1509         if ((ivalid & ATTR_CTIME) && trust_local_cmtime) {
1769                 arg->valid |= FATTR_CTIME;       1510                 arg->valid |= FATTR_CTIME;
1770                 arg->ctime = iattr->ia_ctime.    1511                 arg->ctime = iattr->ia_ctime.tv_sec;
1771                 arg->ctimensec = iattr->ia_ct    1512                 arg->ctimensec = iattr->ia_ctime.tv_nsec;
1772         }                                        1513         }
1773 }                                                1514 }
1774                                                  1515 
1775 /*                                               1516 /*
1776  * Prevent concurrent writepages on inode        1517  * Prevent concurrent writepages on inode
1777  *                                               1518  *
1778  * This is done by adding a negative bias to     1519  * This is done by adding a negative bias to the inode write counter
1779  * and waiting for all pending writes to fini    1520  * and waiting for all pending writes to finish.
1780  */                                              1521  */
1781 void fuse_set_nowrite(struct inode *inode)       1522 void fuse_set_nowrite(struct inode *inode)
1782 {                                                1523 {
1783         struct fuse_inode *fi = get_fuse_inod    1524         struct fuse_inode *fi = get_fuse_inode(inode);
1784                                                  1525 
1785         BUG_ON(!inode_is_locked(inode));         1526         BUG_ON(!inode_is_locked(inode));
1786                                                  1527 
1787         spin_lock(&fi->lock);                    1528         spin_lock(&fi->lock);
1788         BUG_ON(fi->writectr < 0);                1529         BUG_ON(fi->writectr < 0);
1789         fi->writectr += FUSE_NOWRITE;            1530         fi->writectr += FUSE_NOWRITE;
1790         spin_unlock(&fi->lock);                  1531         spin_unlock(&fi->lock);
1791         wait_event(fi->page_waitq, fi->writec    1532         wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1792 }                                                1533 }
1793                                                  1534 
1794 /*                                               1535 /*
1795  * Allow writepages on inode                     1536  * Allow writepages on inode
1796  *                                               1537  *
1797  * Remove the bias from the writecounter and     1538  * Remove the bias from the writecounter and send any queued
1798  * writepages.                                   1539  * writepages.
1799  */                                              1540  */
1800 static void __fuse_release_nowrite(struct ino    1541 static void __fuse_release_nowrite(struct inode *inode)
1801 {                                                1542 {
1802         struct fuse_inode *fi = get_fuse_inod    1543         struct fuse_inode *fi = get_fuse_inode(inode);
1803                                                  1544 
1804         BUG_ON(fi->writectr != FUSE_NOWRITE);    1545         BUG_ON(fi->writectr != FUSE_NOWRITE);
1805         fi->writectr = 0;                        1546         fi->writectr = 0;
1806         fuse_flush_writepages(inode);            1547         fuse_flush_writepages(inode);
1807 }                                                1548 }
1808                                                  1549 
1809 void fuse_release_nowrite(struct inode *inode    1550 void fuse_release_nowrite(struct inode *inode)
1810 {                                                1551 {
1811         struct fuse_inode *fi = get_fuse_inod    1552         struct fuse_inode *fi = get_fuse_inode(inode);
1812                                                  1553 
1813         spin_lock(&fi->lock);                    1554         spin_lock(&fi->lock);
1814         __fuse_release_nowrite(inode);           1555         __fuse_release_nowrite(inode);
1815         spin_unlock(&fi->lock);                  1556         spin_unlock(&fi->lock);
1816 }                                                1557 }
1817                                                  1558 
1818 static void fuse_setattr_fill(struct fuse_con    1559 static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
1819                               struct inode *i    1560                               struct inode *inode,
1820                               struct fuse_set    1561                               struct fuse_setattr_in *inarg_p,
1821                               struct fuse_att    1562                               struct fuse_attr_out *outarg_p)
1822 {                                                1563 {
1823         args->opcode = FUSE_SETATTR;             1564         args->opcode = FUSE_SETATTR;
1824         args->nodeid = get_node_id(inode);       1565         args->nodeid = get_node_id(inode);
1825         args->in_numargs = 1;                    1566         args->in_numargs = 1;
1826         args->in_args[0].size = sizeof(*inarg    1567         args->in_args[0].size = sizeof(*inarg_p);
1827         args->in_args[0].value = inarg_p;        1568         args->in_args[0].value = inarg_p;
1828         args->out_numargs = 1;                   1569         args->out_numargs = 1;
1829         args->out_args[0].size = sizeof(*outa    1570         args->out_args[0].size = sizeof(*outarg_p);
1830         args->out_args[0].value = outarg_p;      1571         args->out_args[0].value = outarg_p;
1831 }                                                1572 }
1832                                                  1573 
1833 /*                                               1574 /*
1834  * Flush inode->i_mtime to the server            1575  * Flush inode->i_mtime to the server
1835  */                                              1576  */
1836 int fuse_flush_times(struct inode *inode, str    1577 int fuse_flush_times(struct inode *inode, struct fuse_file *ff)
1837 {                                                1578 {
1838         struct fuse_mount *fm = get_fuse_moun    1579         struct fuse_mount *fm = get_fuse_mount(inode);
1839         FUSE_ARGS(args);                         1580         FUSE_ARGS(args);
1840         struct fuse_setattr_in inarg;            1581         struct fuse_setattr_in inarg;
1841         struct fuse_attr_out outarg;             1582         struct fuse_attr_out outarg;
1842                                                  1583 
1843         memset(&inarg, 0, sizeof(inarg));        1584         memset(&inarg, 0, sizeof(inarg));
1844         memset(&outarg, 0, sizeof(outarg));      1585         memset(&outarg, 0, sizeof(outarg));
1845                                                  1586 
1846         inarg.valid = FATTR_MTIME;               1587         inarg.valid = FATTR_MTIME;
1847         inarg.mtime = inode_get_mtime_sec(ino !! 1588         inarg.mtime = inode->i_mtime.tv_sec;
1848         inarg.mtimensec = inode_get_mtime_nse !! 1589         inarg.mtimensec = inode->i_mtime.tv_nsec;
1849         if (fm->fc->minor >= 23) {               1590         if (fm->fc->minor >= 23) {
1850                 inarg.valid |= FATTR_CTIME;      1591                 inarg.valid |= FATTR_CTIME;
1851                 inarg.ctime = inode_get_ctime !! 1592                 inarg.ctime = inode->i_ctime.tv_sec;
1852                 inarg.ctimensec = inode_get_c !! 1593                 inarg.ctimensec = inode->i_ctime.tv_nsec;
1853         }                                        1594         }
1854         if (ff) {                                1595         if (ff) {
1855                 inarg.valid |= FATTR_FH;         1596                 inarg.valid |= FATTR_FH;
1856                 inarg.fh = ff->fh;               1597                 inarg.fh = ff->fh;
1857         }                                        1598         }
1858         fuse_setattr_fill(fm->fc, &args, inod    1599         fuse_setattr_fill(fm->fc, &args, inode, &inarg, &outarg);
1859                                                  1600 
1860         return fuse_simple_request(fm, &args)    1601         return fuse_simple_request(fm, &args);
1861 }                                                1602 }
1862                                                  1603 
1863 /*                                               1604 /*
1864  * Set attributes, and at the same time refre    1605  * Set attributes, and at the same time refresh them.
1865  *                                               1606  *
1866  * Truncation is slightly complicated, becaus    1607  * Truncation is slightly complicated, because the 'truncate' request
1867  * may fail, in which case we don't want to t    1608  * may fail, in which case we don't want to touch the mapping.
1868  * vmtruncate() doesn't allow for this case,     1609  * vmtruncate() doesn't allow for this case, so do the rlimit checking
1869  * and the actual truncation by hand.            1610  * and the actual truncation by hand.
1870  */                                              1611  */
1871 int fuse_do_setattr(struct dentry *dentry, st    1612 int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1872                     struct file *file)           1613                     struct file *file)
1873 {                                                1614 {
1874         struct inode *inode = d_inode(dentry)    1615         struct inode *inode = d_inode(dentry);
1875         struct fuse_mount *fm = get_fuse_moun    1616         struct fuse_mount *fm = get_fuse_mount(inode);
1876         struct fuse_conn *fc = fm->fc;           1617         struct fuse_conn *fc = fm->fc;
1877         struct fuse_inode *fi = get_fuse_inod    1618         struct fuse_inode *fi = get_fuse_inode(inode);
1878         struct address_space *mapping = inode << 
1879         FUSE_ARGS(args);                         1619         FUSE_ARGS(args);
1880         struct fuse_setattr_in inarg;            1620         struct fuse_setattr_in inarg;
1881         struct fuse_attr_out outarg;             1621         struct fuse_attr_out outarg;
1882         bool is_truncate = false;                1622         bool is_truncate = false;
1883         bool is_wb = fc->writeback_cache && S !! 1623         bool is_wb = fc->writeback_cache;
1884         loff_t oldsize;                          1624         loff_t oldsize;
1885         int err;                                 1625         int err;
1886         bool trust_local_cmtime = is_wb;      !! 1626         bool trust_local_cmtime = is_wb && S_ISREG(inode->i_mode);
1887         bool fault_blocked = false;              1627         bool fault_blocked = false;
1888                                                  1628 
1889         if (!fc->default_permissions)            1629         if (!fc->default_permissions)
1890                 attr->ia_valid |= ATTR_FORCE;    1630                 attr->ia_valid |= ATTR_FORCE;
1891                                                  1631 
1892         err = setattr_prepare(&nop_mnt_idmap, !! 1632         err = setattr_prepare(&init_user_ns, dentry, attr);
1893         if (err)                                 1633         if (err)
1894                 return err;                      1634                 return err;
1895                                                  1635 
1896         if (attr->ia_valid & ATTR_SIZE) {        1636         if (attr->ia_valid & ATTR_SIZE) {
1897                 if (WARN_ON(!S_ISREG(inode->i    1637                 if (WARN_ON(!S_ISREG(inode->i_mode)))
1898                         return -EIO;             1638                         return -EIO;
1899                 is_truncate = true;              1639                 is_truncate = true;
1900         }                                        1640         }
1901                                                  1641 
1902         if (FUSE_IS_DAX(inode) && is_truncate    1642         if (FUSE_IS_DAX(inode) && is_truncate) {
1903                 filemap_invalidate_lock(mappi !! 1643                 down_write(&fi->i_mmap_sem);
1904                 fault_blocked = true;            1644                 fault_blocked = true;
1905                 err = fuse_dax_break_layouts(    1645                 err = fuse_dax_break_layouts(inode, 0, 0);
1906                 if (err) {                       1646                 if (err) {
1907                         filemap_invalidate_un !! 1647                         up_write(&fi->i_mmap_sem);
1908                         return err;              1648                         return err;
1909                 }                                1649                 }
1910         }                                        1650         }
1911                                                  1651 
1912         if (attr->ia_valid & ATTR_OPEN) {        1652         if (attr->ia_valid & ATTR_OPEN) {
1913                 /* This is coming from open(.    1653                 /* This is coming from open(..., ... | O_TRUNC); */
1914                 WARN_ON(!(attr->ia_valid & AT    1654                 WARN_ON(!(attr->ia_valid & ATTR_SIZE));
1915                 WARN_ON(attr->ia_size != 0);     1655                 WARN_ON(attr->ia_size != 0);
1916                 if (fc->atomic_o_trunc) {        1656                 if (fc->atomic_o_trunc) {
1917                         /*                       1657                         /*
1918                          * No need to send re    1658                          * No need to send request to userspace, since actual
1919                          * truncation has alr    1659                          * truncation has already been done by OPEN.  But still
1920                          * need to truncate p    1660                          * need to truncate page cache.
1921                          */                      1661                          */
1922                         i_size_write(inode, 0    1662                         i_size_write(inode, 0);
1923                         truncate_pagecache(in    1663                         truncate_pagecache(inode, 0);
1924                         goto out;                1664                         goto out;
1925                 }                                1665                 }
1926                 file = NULL;                     1666                 file = NULL;
1927         }                                        1667         }
1928                                                  1668 
1929         /* Flush dirty data/metadata before n    1669         /* Flush dirty data/metadata before non-truncate SETATTR */
1930         if (is_wb &&                          !! 1670         if (is_wb && S_ISREG(inode->i_mode) &&
1931             attr->ia_valid &                     1671             attr->ia_valid &
1932                         (ATTR_MODE | ATTR_UID    1672                         (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET |
1933                          ATTR_TIMES_SET)) {      1673                          ATTR_TIMES_SET)) {
1934                 err = write_inode_now(inode,     1674                 err = write_inode_now(inode, true);
1935                 if (err)                         1675                 if (err)
1936                         return err;              1676                         return err;
1937                                                  1677 
1938                 fuse_set_nowrite(inode);         1678                 fuse_set_nowrite(inode);
1939                 fuse_release_nowrite(inode);     1679                 fuse_release_nowrite(inode);
1940         }                                        1680         }
1941                                                  1681 
1942         if (is_truncate) {                       1682         if (is_truncate) {
1943                 fuse_set_nowrite(inode);         1683                 fuse_set_nowrite(inode);
1944                 set_bit(FUSE_I_SIZE_UNSTABLE,    1684                 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1945                 if (trust_local_cmtime && att    1685                 if (trust_local_cmtime && attr->ia_size != inode->i_size)
1946                         attr->ia_valid |= ATT    1686                         attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1947         }                                        1687         }
1948                                                  1688 
1949         memset(&inarg, 0, sizeof(inarg));        1689         memset(&inarg, 0, sizeof(inarg));
1950         memset(&outarg, 0, sizeof(outarg));      1690         memset(&outarg, 0, sizeof(outarg));
1951         iattr_to_fattr(fc, attr, &inarg, trus    1691         iattr_to_fattr(fc, attr, &inarg, trust_local_cmtime);
1952         if (file) {                              1692         if (file) {
1953                 struct fuse_file *ff = file->    1693                 struct fuse_file *ff = file->private_data;
1954                 inarg.valid |= FATTR_FH;         1694                 inarg.valid |= FATTR_FH;
1955                 inarg.fh = ff->fh;               1695                 inarg.fh = ff->fh;
1956         }                                        1696         }
1957                                                  1697 
1958         /* Kill suid/sgid for non-directory c    1698         /* Kill suid/sgid for non-directory chown unconditionally */
1959         if (fc->handle_killpriv_v2 && !S_ISDI    1699         if (fc->handle_killpriv_v2 && !S_ISDIR(inode->i_mode) &&
1960             attr->ia_valid & (ATTR_UID | ATTR    1700             attr->ia_valid & (ATTR_UID | ATTR_GID))
1961                 inarg.valid |= FATTR_KILL_SUI    1701                 inarg.valid |= FATTR_KILL_SUIDGID;
1962                                                  1702 
1963         if (attr->ia_valid & ATTR_SIZE) {        1703         if (attr->ia_valid & ATTR_SIZE) {
1964                 /* For mandatory locking in t    1704                 /* For mandatory locking in truncate */
1965                 inarg.valid |= FATTR_LOCKOWNE    1705                 inarg.valid |= FATTR_LOCKOWNER;
1966                 inarg.lock_owner = fuse_lock_    1706                 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1967                                                  1707 
1968                 /* Kill suid/sgid for truncat    1708                 /* Kill suid/sgid for truncate only if no CAP_FSETID */
1969                 if (fc->handle_killpriv_v2 &&    1709                 if (fc->handle_killpriv_v2 && !capable(CAP_FSETID))
1970                         inarg.valid |= FATTR_    1710                         inarg.valid |= FATTR_KILL_SUIDGID;
1971         }                                        1711         }
1972         fuse_setattr_fill(fc, &args, inode, &    1712         fuse_setattr_fill(fc, &args, inode, &inarg, &outarg);
1973         err = fuse_simple_request(fm, &args);    1713         err = fuse_simple_request(fm, &args);
1974         if (err) {                               1714         if (err) {
1975                 if (err == -EINTR)               1715                 if (err == -EINTR)
1976                         fuse_invalidate_attr(    1716                         fuse_invalidate_attr(inode);
1977                 goto error;                      1717                 goto error;
1978         }                                        1718         }
1979                                                  1719 
1980         if (fuse_invalid_attr(&outarg.attr) |    1720         if (fuse_invalid_attr(&outarg.attr) ||
1981             inode_wrong_type(inode, outarg.at !! 1721             (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1982                 fuse_make_bad(inode);            1722                 fuse_make_bad(inode);
1983                 err = -EIO;                      1723                 err = -EIO;
1984                 goto error;                      1724                 goto error;
1985         }                                        1725         }
1986                                                  1726 
1987         spin_lock(&fi->lock);                    1727         spin_lock(&fi->lock);
1988         /* the kernel maintains i_mtime local    1728         /* the kernel maintains i_mtime locally */
1989         if (trust_local_cmtime) {                1729         if (trust_local_cmtime) {
1990                 if (attr->ia_valid & ATTR_MTI    1730                 if (attr->ia_valid & ATTR_MTIME)
1991                         inode_set_mtime_to_ts !! 1731                         inode->i_mtime = attr->ia_mtime;
1992                 if (attr->ia_valid & ATTR_CTI    1732                 if (attr->ia_valid & ATTR_CTIME)
1993                         inode_set_ctime_to_ts !! 1733                         inode->i_ctime = attr->ia_ctime;
1994                 /* FIXME: clear I_DIRTY_SYNC?    1734                 /* FIXME: clear I_DIRTY_SYNC? */
1995         }                                        1735         }
1996                                                  1736 
1997         fuse_change_attributes_common(inode,  !! 1737         fuse_change_attributes_common(inode, &outarg.attr,
1998                                       ATTR_TI !! 1738                                       attr_timeout(&outarg));
1999                                       fuse_ge << 
2000         oldsize = inode->i_size;                 1739         oldsize = inode->i_size;
2001         /* see the comment in fuse_change_att    1740         /* see the comment in fuse_change_attributes() */
2002         if (!is_wb || is_truncate)            !! 1741         if (!is_wb || is_truncate || !S_ISREG(inode->i_mode))
2003                 i_size_write(inode, outarg.at    1742                 i_size_write(inode, outarg.attr.size);
2004                                                  1743 
2005         if (is_truncate) {                       1744         if (is_truncate) {
2006                 /* NOTE: this may release/rea    1745                 /* NOTE: this may release/reacquire fi->lock */
2007                 __fuse_release_nowrite(inode)    1746                 __fuse_release_nowrite(inode);
2008         }                                        1747         }
2009         spin_unlock(&fi->lock);                  1748         spin_unlock(&fi->lock);
2010                                                  1749 
2011         /*                                       1750         /*
2012          * Only call invalidate_inode_pages2(    1751          * Only call invalidate_inode_pages2() after removing
2013          * FUSE_NOWRITE, otherwise fuse_laund !! 1752          * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
2014          */                                      1753          */
2015         if ((is_truncate || !is_wb) &&           1754         if ((is_truncate || !is_wb) &&
2016             S_ISREG(inode->i_mode) && oldsize    1755             S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
2017                 truncate_pagecache(inode, out    1756                 truncate_pagecache(inode, outarg.attr.size);
2018                 invalidate_inode_pages2(mappi !! 1757                 invalidate_inode_pages2(inode->i_mapping);
2019         }                                        1758         }
2020                                                  1759 
2021         clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->    1760         clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2022 out:                                             1761 out:
2023         if (fault_blocked)                       1762         if (fault_blocked)
2024                 filemap_invalidate_unlock(map !! 1763                 up_write(&fi->i_mmap_sem);
2025                                                  1764 
2026         return 0;                                1765         return 0;
2027                                                  1766 
2028 error:                                           1767 error:
2029         if (is_truncate)                         1768         if (is_truncate)
2030                 fuse_release_nowrite(inode);     1769                 fuse_release_nowrite(inode);
2031                                                  1770 
2032         clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->    1771         clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
2033                                                  1772 
2034         if (fault_blocked)                       1773         if (fault_blocked)
2035                 filemap_invalidate_unlock(map !! 1774                 up_write(&fi->i_mmap_sem);
2036         return err;                              1775         return err;
2037 }                                                1776 }
2038                                                  1777 
2039 static int fuse_setattr(struct mnt_idmap *idm !! 1778 static int fuse_setattr(struct user_namespace *mnt_userns, struct dentry *entry,
2040                         struct iattr *attr)      1779                         struct iattr *attr)
2041 {                                                1780 {
2042         struct inode *inode = d_inode(entry);    1781         struct inode *inode = d_inode(entry);
2043         struct fuse_conn *fc = get_fuse_conn(    1782         struct fuse_conn *fc = get_fuse_conn(inode);
2044         struct file *file = (attr->ia_valid &    1783         struct file *file = (attr->ia_valid & ATTR_FILE) ? attr->ia_file : NULL;
2045         int ret;                                 1784         int ret;
2046                                                  1785 
2047         if (fuse_is_bad(inode))                  1786         if (fuse_is_bad(inode))
2048                 return -EIO;                     1787                 return -EIO;
2049                                                  1788 
2050         if (!fuse_allow_current_process(get_f    1789         if (!fuse_allow_current_process(get_fuse_conn(inode)))
2051                 return -EACCES;                  1790                 return -EACCES;
2052                                                  1791 
2053         if (attr->ia_valid & (ATTR_KILL_SUID     1792         if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
2054                 attr->ia_valid &= ~(ATTR_KILL    1793                 attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
2055                                     ATTR_MODE    1794                                     ATTR_MODE);
2056                                                  1795 
2057                 /*                               1796                 /*
2058                  * The only sane way to relia    1797                  * The only sane way to reliably kill suid/sgid is to do it in
2059                  * the userspace filesystem      1798                  * the userspace filesystem
2060                  *                               1799                  *
2061                  * This should be done on wri    1800                  * This should be done on write(), truncate() and chown().
2062                  */                              1801                  */
2063                 if (!fc->handle_killpriv && !    1802                 if (!fc->handle_killpriv && !fc->handle_killpriv_v2) {
2064                         /*                       1803                         /*
2065                          * ia_mode calculatio    1804                          * ia_mode calculation may have used stale i_mode.
2066                          * Refresh and recalc    1805                          * Refresh and recalculate.
2067                          */                      1806                          */
2068                         ret = fuse_do_getattr    1807                         ret = fuse_do_getattr(inode, NULL, file);
2069                         if (ret)                 1808                         if (ret)
2070                                 return ret;      1809                                 return ret;
2071                                                  1810 
2072                         attr->ia_mode = inode    1811                         attr->ia_mode = inode->i_mode;
2073                         if (inode->i_mode & S    1812                         if (inode->i_mode & S_ISUID) {
2074                                 attr->ia_vali    1813                                 attr->ia_valid |= ATTR_MODE;
2075                                 attr->ia_mode    1814                                 attr->ia_mode &= ~S_ISUID;
2076                         }                        1815                         }
2077                         if ((inode->i_mode &     1816                         if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
2078                                 attr->ia_vali    1817                                 attr->ia_valid |= ATTR_MODE;
2079                                 attr->ia_mode    1818                                 attr->ia_mode &= ~S_ISGID;
2080                         }                        1819                         }
2081                 }                                1820                 }
2082         }                                        1821         }
2083         if (!attr->ia_valid)                     1822         if (!attr->ia_valid)
2084                 return 0;                        1823                 return 0;
2085                                                  1824 
2086         ret = fuse_do_setattr(entry, attr, fi    1825         ret = fuse_do_setattr(entry, attr, file);
2087         if (!ret) {                              1826         if (!ret) {
2088                 /*                               1827                 /*
2089                  * If filesystem supports acl    1828                  * If filesystem supports acls it may have updated acl xattrs in
2090                  * the filesystem, so forget     1829                  * the filesystem, so forget cached acls for the inode.
2091                  */                              1830                  */
2092                 if (fc->posix_acl)               1831                 if (fc->posix_acl)
2093                         forget_all_cached_acl    1832                         forget_all_cached_acls(inode);
2094                                                  1833 
2095                 /* Directory mode changed, ma    1834                 /* Directory mode changed, may need to revalidate access */
2096                 if (d_is_dir(entry) && (attr-    1835                 if (d_is_dir(entry) && (attr->ia_valid & ATTR_MODE))
2097                         fuse_invalidate_entry    1836                         fuse_invalidate_entry_cache(entry);
2098         }                                        1837         }
2099         return ret;                              1838         return ret;
2100 }                                                1839 }
2101                                                  1840 
2102 static int fuse_getattr(struct mnt_idmap *idm !! 1841 static int fuse_getattr(struct user_namespace *mnt_userns,
2103                         const struct path *pa    1842                         const struct path *path, struct kstat *stat,
2104                         u32 request_mask, uns    1843                         u32 request_mask, unsigned int flags)
2105 {                                                1844 {
2106         struct inode *inode = d_inode(path->d    1845         struct inode *inode = d_inode(path->dentry);
2107         struct fuse_conn *fc = get_fuse_conn(    1846         struct fuse_conn *fc = get_fuse_conn(inode);
2108                                                  1847 
2109         if (fuse_is_bad(inode))                  1848         if (fuse_is_bad(inode))
2110                 return -EIO;                     1849                 return -EIO;
2111                                                  1850 
2112         if (!fuse_allow_current_process(fc))     1851         if (!fuse_allow_current_process(fc)) {
2113                 if (!request_mask) {             1852                 if (!request_mask) {
2114                         /*                       1853                         /*
2115                          * If user explicitly    1854                          * If user explicitly requested *nothing* then don't
2116                          * error out, but ret    1855                          * error out, but return st_dev only.
2117                          */                      1856                          */
2118                         stat->result_mask = 0    1857                         stat->result_mask = 0;
2119                         stat->dev = inode->i_    1858                         stat->dev = inode->i_sb->s_dev;
2120                         return 0;                1859                         return 0;
2121                 }                                1860                 }
2122                 return -EACCES;                  1861                 return -EACCES;
2123         }                                        1862         }
2124                                                  1863 
2125         return fuse_update_get_attr(inode, NU    1864         return fuse_update_get_attr(inode, NULL, stat, request_mask, flags);
2126 }                                                1865 }
2127                                                  1866 
2128 static const struct inode_operations fuse_dir    1867 static const struct inode_operations fuse_dir_inode_operations = {
2129         .lookup         = fuse_lookup,           1868         .lookup         = fuse_lookup,
2130         .mkdir          = fuse_mkdir,            1869         .mkdir          = fuse_mkdir,
2131         .symlink        = fuse_symlink,          1870         .symlink        = fuse_symlink,
2132         .unlink         = fuse_unlink,           1871         .unlink         = fuse_unlink,
2133         .rmdir          = fuse_rmdir,            1872         .rmdir          = fuse_rmdir,
2134         .rename         = fuse_rename2,          1873         .rename         = fuse_rename2,
2135         .link           = fuse_link,             1874         .link           = fuse_link,
2136         .setattr        = fuse_setattr,          1875         .setattr        = fuse_setattr,
2137         .create         = fuse_create,           1876         .create         = fuse_create,
2138         .atomic_open    = fuse_atomic_open,      1877         .atomic_open    = fuse_atomic_open,
2139         .tmpfile        = fuse_tmpfile,       << 
2140         .mknod          = fuse_mknod,            1878         .mknod          = fuse_mknod,
2141         .permission     = fuse_permission,       1879         .permission     = fuse_permission,
2142         .getattr        = fuse_getattr,          1880         .getattr        = fuse_getattr,
2143         .listxattr      = fuse_listxattr,        1881         .listxattr      = fuse_listxattr,
2144         .get_inode_acl  = fuse_get_inode_acl, << 
2145         .get_acl        = fuse_get_acl,          1882         .get_acl        = fuse_get_acl,
2146         .set_acl        = fuse_set_acl,          1883         .set_acl        = fuse_set_acl,
2147         .fileattr_get   = fuse_fileattr_get,  << 
2148         .fileattr_set   = fuse_fileattr_set,  << 
2149 };                                               1884 };
2150                                                  1885 
2151 static const struct file_operations fuse_dir_    1886 static const struct file_operations fuse_dir_operations = {
2152         .llseek         = generic_file_llseek    1887         .llseek         = generic_file_llseek,
2153         .read           = generic_read_dir,      1888         .read           = generic_read_dir,
2154         .iterate_shared = fuse_readdir,          1889         .iterate_shared = fuse_readdir,
2155         .open           = fuse_dir_open,         1890         .open           = fuse_dir_open,
2156         .release        = fuse_dir_release,      1891         .release        = fuse_dir_release,
2157         .fsync          = fuse_dir_fsync,        1892         .fsync          = fuse_dir_fsync,
2158         .unlocked_ioctl = fuse_dir_ioctl,        1893         .unlocked_ioctl = fuse_dir_ioctl,
2159         .compat_ioctl   = fuse_dir_compat_ioc    1894         .compat_ioctl   = fuse_dir_compat_ioctl,
2160 };                                               1895 };
2161                                                  1896 
2162 static const struct inode_operations fuse_com    1897 static const struct inode_operations fuse_common_inode_operations = {
2163         .setattr        = fuse_setattr,          1898         .setattr        = fuse_setattr,
2164         .permission     = fuse_permission,       1899         .permission     = fuse_permission,
2165         .getattr        = fuse_getattr,          1900         .getattr        = fuse_getattr,
2166         .listxattr      = fuse_listxattr,        1901         .listxattr      = fuse_listxattr,
2167         .get_inode_acl  = fuse_get_inode_acl, << 
2168         .get_acl        = fuse_get_acl,          1902         .get_acl        = fuse_get_acl,
2169         .set_acl        = fuse_set_acl,          1903         .set_acl        = fuse_set_acl,
2170         .fileattr_get   = fuse_fileattr_get,  << 
2171         .fileattr_set   = fuse_fileattr_set,  << 
2172 };                                               1904 };
2173                                                  1905 
2174 static const struct inode_operations fuse_sym    1906 static const struct inode_operations fuse_symlink_inode_operations = {
2175         .setattr        = fuse_setattr,          1907         .setattr        = fuse_setattr,
2176         .get_link       = fuse_get_link,         1908         .get_link       = fuse_get_link,
2177         .getattr        = fuse_getattr,          1909         .getattr        = fuse_getattr,
2178         .listxattr      = fuse_listxattr,        1910         .listxattr      = fuse_listxattr,
2179 };                                               1911 };
2180                                                  1912 
2181 void fuse_init_common(struct inode *inode)       1913 void fuse_init_common(struct inode *inode)
2182 {                                                1914 {
2183         inode->i_op = &fuse_common_inode_oper    1915         inode->i_op = &fuse_common_inode_operations;
2184 }                                                1916 }
2185                                                  1917 
2186 void fuse_init_dir(struct inode *inode)          1918 void fuse_init_dir(struct inode *inode)
2187 {                                                1919 {
2188         struct fuse_inode *fi = get_fuse_inod    1920         struct fuse_inode *fi = get_fuse_inode(inode);
2189                                                  1921 
2190         inode->i_op = &fuse_dir_inode_operati    1922         inode->i_op = &fuse_dir_inode_operations;
2191         inode->i_fop = &fuse_dir_operations;     1923         inode->i_fop = &fuse_dir_operations;
2192                                                  1924 
2193         spin_lock_init(&fi->rdc.lock);           1925         spin_lock_init(&fi->rdc.lock);
2194         fi->rdc.cached = false;                  1926         fi->rdc.cached = false;
2195         fi->rdc.size = 0;                        1927         fi->rdc.size = 0;
2196         fi->rdc.pos = 0;                         1928         fi->rdc.pos = 0;
2197         fi->rdc.version = 0;                     1929         fi->rdc.version = 0;
2198 }                                                1930 }
2199                                                  1931 
2200 static int fuse_symlink_read_folio(struct fil !! 1932 static int fuse_symlink_readpage(struct file *null, struct page *page)
2201 {                                                1933 {
2202         int err = fuse_readlink_page(folio->m !! 1934         int err = fuse_readlink_page(page->mapping->host, page);
2203                                                  1935 
2204         if (!err)                                1936         if (!err)
2205                 folio_mark_uptodate(folio);   !! 1937                 SetPageUptodate(page);
2206                                                  1938 
2207         folio_unlock(folio);                  !! 1939         unlock_page(page);
2208                                                  1940 
2209         return err;                              1941         return err;
2210 }                                                1942 }
2211                                                  1943 
2212 static const struct address_space_operations     1944 static const struct address_space_operations fuse_symlink_aops = {
2213         .read_folio     = fuse_symlink_read_f !! 1945         .readpage       = fuse_symlink_readpage,
2214 };                                               1946 };
2215                                                  1947 
2216 void fuse_init_symlink(struct inode *inode)      1948 void fuse_init_symlink(struct inode *inode)
2217 {                                                1949 {
2218         inode->i_op = &fuse_symlink_inode_ope    1950         inode->i_op = &fuse_symlink_inode_operations;
2219         inode->i_data.a_ops = &fuse_symlink_a    1951         inode->i_data.a_ops = &fuse_symlink_aops;
2220         inode_nohighmem(inode);                  1952         inode_nohighmem(inode);
2221 }                                                1953 }
2222                                                  1954 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php