~ [ 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-3.10.108)


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

~ [ 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