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

TOMOYO Linux Cross Reference
Linux/fs/overlayfs/super.c

Version: ~ [ linux-5.10-rc5 ] ~ [ linux-5.9.10 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.79 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.159 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.208 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.245 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.245 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *
  3  * Copyright (C) 2011 Novell Inc.
  4  *
  5  * This program is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 as published by
  7  * the Free Software Foundation.
  8  */
  9 
 10 #include <uapi/linux/magic.h>
 11 #include <linux/fs.h>
 12 #include <linux/namei.h>
 13 #include <linux/xattr.h>
 14 #include <linux/mount.h>
 15 #include <linux/parser.h>
 16 #include <linux/module.h>
 17 #include <linux/statfs.h>
 18 #include <linux/seq_file.h>
 19 #include <linux/posix_acl_xattr.h>
 20 #include "overlayfs.h"
 21 
 22 MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
 23 MODULE_DESCRIPTION("Overlay filesystem");
 24 MODULE_LICENSE("GPL");
 25 
 26 
 27 struct ovl_dir_cache;
 28 
 29 #define OVL_MAX_STACK 500
 30 
 31 static bool ovl_redirect_dir_def = IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR);
 32 module_param_named(redirect_dir, ovl_redirect_dir_def, bool, 0644);
 33 MODULE_PARM_DESC(ovl_redirect_dir_def,
 34                  "Default to on or off for the redirect_dir feature");
 35 
 36 static bool ovl_redirect_always_follow =
 37         IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW);
 38 module_param_named(redirect_always_follow, ovl_redirect_always_follow,
 39                    bool, 0644);
 40 MODULE_PARM_DESC(ovl_redirect_always_follow,
 41                  "Follow redirects even if redirect_dir feature is turned off");
 42 
 43 static bool ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX);
 44 module_param_named(index, ovl_index_def, bool, 0644);
 45 MODULE_PARM_DESC(ovl_index_def,
 46                  "Default to on or off for the inodes index feature");
 47 
 48 static void ovl_entry_stack_free(struct ovl_entry *oe)
 49 {
 50         unsigned int i;
 51 
 52         for (i = 0; i < oe->numlower; i++)
 53                 dput(oe->lowerstack[i].dentry);
 54 }
 55 
 56 static void ovl_dentry_release(struct dentry *dentry)
 57 {
 58         struct ovl_entry *oe = dentry->d_fsdata;
 59 
 60         if (oe) {
 61                 ovl_entry_stack_free(oe);
 62                 kfree_rcu(oe, rcu);
 63         }
 64 }
 65 
 66 static int ovl_check_append_only(struct inode *inode, int flag)
 67 {
 68         /*
 69          * This test was moot in vfs may_open() because overlay inode does
 70          * not have the S_APPEND flag, so re-check on real upper inode
 71          */
 72         if (IS_APPEND(inode)) {
 73                 if  ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND))
 74                         return -EPERM;
 75                 if (flag & O_TRUNC)
 76                         return -EPERM;
 77         }
 78 
 79         return 0;
 80 }
 81 
 82 static struct dentry *ovl_d_real(struct dentry *dentry,
 83                                  const struct inode *inode,
 84                                  unsigned int open_flags, unsigned int flags)
 85 {
 86         struct dentry *real;
 87         int err;
 88 
 89         if (flags & D_REAL_UPPER)
 90                 return ovl_dentry_upper(dentry);
 91 
 92         if (!d_is_reg(dentry)) {
 93                 if (!inode || inode == d_inode(dentry))
 94                         return dentry;
 95                 goto bug;
 96         }
 97 
 98         if (open_flags) {
 99                 err = ovl_open_maybe_copy_up(dentry, open_flags);
100                 if (err)
101                         return ERR_PTR(err);
102         }
103 
104         real = ovl_dentry_upper(dentry);
105         if (real && (!inode || inode == d_inode(real))) {
106                 if (!inode) {
107                         err = ovl_check_append_only(d_inode(real), open_flags);
108                         if (err)
109                                 return ERR_PTR(err);
110                 }
111                 return real;
112         }
113 
114         real = ovl_dentry_lower(dentry);
115         if (!real)
116                 goto bug;
117 
118         /* Handle recursion */
119         real = d_real(real, inode, open_flags, 0);
120 
121         if (!inode || inode == d_inode(real))
122                 return real;
123 bug:
124         WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry,
125              inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
126         return dentry;
127 }
128 
129 static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
130 {
131         struct ovl_entry *oe = dentry->d_fsdata;
132         unsigned int i;
133         int ret = 1;
134 
135         for (i = 0; i < oe->numlower; i++) {
136                 struct dentry *d = oe->lowerstack[i].dentry;
137 
138                 if (d->d_flags & DCACHE_OP_REVALIDATE) {
139                         ret = d->d_op->d_revalidate(d, flags);
140                         if (ret < 0)
141                                 return ret;
142                         if (!ret) {
143                                 if (!(flags & LOOKUP_RCU))
144                                         d_invalidate(d);
145                                 return -ESTALE;
146                         }
147                 }
148         }
149         return 1;
150 }
151 
152 static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
153 {
154         struct ovl_entry *oe = dentry->d_fsdata;
155         unsigned int i;
156         int ret = 1;
157 
158         for (i = 0; i < oe->numlower; i++) {
159                 struct dentry *d = oe->lowerstack[i].dentry;
160 
161                 if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) {
162                         ret = d->d_op->d_weak_revalidate(d, flags);
163                         if (ret <= 0)
164                                 break;
165                 }
166         }
167         return ret;
168 }
169 
170 static const struct dentry_operations ovl_dentry_operations = {
171         .d_release = ovl_dentry_release,
172         .d_real = ovl_d_real,
173 };
174 
175 static const struct dentry_operations ovl_reval_dentry_operations = {
176         .d_release = ovl_dentry_release,
177         .d_real = ovl_d_real,
178         .d_revalidate = ovl_dentry_revalidate,
179         .d_weak_revalidate = ovl_dentry_weak_revalidate,
180 };
181 
182 static struct kmem_cache *ovl_inode_cachep;
183 
184 static struct inode *ovl_alloc_inode(struct super_block *sb)
185 {
186         struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL);
187 
188         if (!oi)
189                 return NULL;
190 
191         oi->cache = NULL;
192         oi->redirect = NULL;
193         oi->version = 0;
194         oi->flags = 0;
195         oi->__upperdentry = NULL;
196         oi->lower = NULL;
197         mutex_init(&oi->lock);
198 
199         return &oi->vfs_inode;
200 }
201 
202 static void ovl_i_callback(struct rcu_head *head)
203 {
204         struct inode *inode = container_of(head, struct inode, i_rcu);
205 
206         kmem_cache_free(ovl_inode_cachep, OVL_I(inode));
207 }
208 
209 static void ovl_destroy_inode(struct inode *inode)
210 {
211         struct ovl_inode *oi = OVL_I(inode);
212 
213         dput(oi->__upperdentry);
214         iput(oi->lower);
215         kfree(oi->redirect);
216         ovl_dir_cache_free(inode);
217         mutex_destroy(&oi->lock);
218 
219         call_rcu(&inode->i_rcu, ovl_i_callback);
220 }
221 
222 static void ovl_free_fs(struct ovl_fs *ofs)
223 {
224         unsigned i;
225 
226         dput(ofs->indexdir);
227         dput(ofs->workdir);
228         if (ofs->workdir_locked)
229                 ovl_inuse_unlock(ofs->workbasedir);
230         dput(ofs->workbasedir);
231         if (ofs->upperdir_locked)
232                 ovl_inuse_unlock(ofs->upper_mnt->mnt_root);
233         mntput(ofs->upper_mnt);
234         for (i = 0; i < ofs->numlower; i++) {
235                 mntput(ofs->lower_layers[i].mnt);
236                 free_anon_bdev(ofs->lower_layers[i].pseudo_dev);
237         }
238         kfree(ofs->lower_layers);
239 
240         kfree(ofs->config.lowerdir);
241         kfree(ofs->config.upperdir);
242         kfree(ofs->config.workdir);
243         kfree(ofs->config.redirect_mode);
244         if (ofs->creator_cred)
245                 put_cred(ofs->creator_cred);
246         kfree(ofs);
247 }
248 
249 static void ovl_put_super(struct super_block *sb)
250 {
251         struct ovl_fs *ofs = sb->s_fs_info;
252 
253         ovl_free_fs(ofs);
254 }
255 
256 /* Sync real dirty inodes in upper filesystem (if it exists) */
257 static int ovl_sync_fs(struct super_block *sb, int wait)
258 {
259         struct ovl_fs *ofs = sb->s_fs_info;
260         struct super_block *upper_sb;
261         int ret;
262 
263         if (!ofs->upper_mnt)
264                 return 0;
265 
266         /*
267          * If this is a sync(2) call or an emergency sync, all the super blocks
268          * will be iterated, including upper_sb, so no need to do anything.
269          *
270          * If this is a syncfs(2) call, then we do need to call
271          * sync_filesystem() on upper_sb, but enough if we do it when being
272          * called with wait == 1.
273          */
274         if (!wait)
275                 return 0;
276 
277         upper_sb = ofs->upper_mnt->mnt_sb;
278 
279         down_read(&upper_sb->s_umount);
280         ret = sync_filesystem(upper_sb);
281         up_read(&upper_sb->s_umount);
282 
283         return ret;
284 }
285 
286 /**
287  * ovl_statfs
288  * @sb: The overlayfs super block
289  * @buf: The struct kstatfs to fill in with stats
290  *
291  * Get the filesystem statistics.  As writes always target the upper layer
292  * filesystem pass the statfs to the upper filesystem (if it exists)
293  */
294 static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
295 {
296         struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
297         struct dentry *root_dentry = dentry->d_sb->s_root;
298         struct path path;
299         int err;
300 
301         ovl_path_real(root_dentry, &path);
302 
303         err = vfs_statfs(&path, buf);
304         if (!err) {
305                 buf->f_namelen = ofs->namelen;
306                 buf->f_type = OVERLAYFS_SUPER_MAGIC;
307         }
308 
309         return err;
310 }
311 
312 /* Will this overlay be forced to mount/remount ro? */
313 static bool ovl_force_readonly(struct ovl_fs *ofs)
314 {
315         return (!ofs->upper_mnt || !ofs->workdir);
316 }
317 
318 static const char *ovl_redirect_mode_def(void)
319 {
320         return ovl_redirect_dir_def ? "on" : "off";
321 }
322 
323 /**
324  * ovl_show_options
325  *
326  * Prints the mount options for a given superblock.
327  * Returns zero; does not fail.
328  */
329 static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
330 {
331         struct super_block *sb = dentry->d_sb;
332         struct ovl_fs *ofs = sb->s_fs_info;
333 
334         seq_show_option(m, "lowerdir", ofs->config.lowerdir);
335         if (ofs->config.upperdir) {
336                 seq_show_option(m, "upperdir", ofs->config.upperdir);
337                 seq_show_option(m, "workdir", ofs->config.workdir);
338         }
339         if (ofs->config.default_permissions)
340                 seq_puts(m, ",default_permissions");
341         if (strcmp(ofs->config.redirect_mode, ovl_redirect_mode_def()) != 0)
342                 seq_printf(m, ",redirect_dir=%s", ofs->config.redirect_mode);
343         if (ofs->config.index != ovl_index_def)
344                 seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off");
345         return 0;
346 }
347 
348 static int ovl_remount(struct super_block *sb, int *flags, char *data)
349 {
350         struct ovl_fs *ofs = sb->s_fs_info;
351 
352         if (!(*flags & SB_RDONLY) && ovl_force_readonly(ofs))
353                 return -EROFS;
354 
355         return 0;
356 }
357 
358 static const struct super_operations ovl_super_operations = {
359         .alloc_inode    = ovl_alloc_inode,
360         .destroy_inode  = ovl_destroy_inode,
361         .drop_inode     = generic_delete_inode,
362         .put_super      = ovl_put_super,
363         .sync_fs        = ovl_sync_fs,
364         .statfs         = ovl_statfs,
365         .show_options   = ovl_show_options,
366         .remount_fs     = ovl_remount,
367 };
368 
369 enum {
370         OPT_LOWERDIR,
371         OPT_UPPERDIR,
372         OPT_WORKDIR,
373         OPT_DEFAULT_PERMISSIONS,
374         OPT_REDIRECT_DIR,
375         OPT_INDEX_ON,
376         OPT_INDEX_OFF,
377         OPT_ERR,
378 };
379 
380 static const match_table_t ovl_tokens = {
381         {OPT_LOWERDIR,                  "lowerdir=%s"},
382         {OPT_UPPERDIR,                  "upperdir=%s"},
383         {OPT_WORKDIR,                   "workdir=%s"},
384         {OPT_DEFAULT_PERMISSIONS,       "default_permissions"},
385         {OPT_REDIRECT_DIR,              "redirect_dir=%s"},
386         {OPT_INDEX_ON,                  "index=on"},
387         {OPT_INDEX_OFF,                 "index=off"},
388         {OPT_ERR,                       NULL}
389 };
390 
391 static char *ovl_next_opt(char **s)
392 {
393         char *sbegin = *s;
394         char *p;
395 
396         if (sbegin == NULL)
397                 return NULL;
398 
399         for (p = sbegin; *p; p++) {
400                 if (*p == '\\') {
401                         p++;
402                         if (!*p)
403                                 break;
404                 } else if (*p == ',') {
405                         *p = '\0';
406                         *s = p + 1;
407                         return sbegin;
408                 }
409         }
410         *s = NULL;
411         return sbegin;
412 }
413 
414 static int ovl_parse_redirect_mode(struct ovl_config *config, const char *mode)
415 {
416         if (strcmp(mode, "on") == 0) {
417                 config->redirect_dir = true;
418                 /*
419                  * Does not make sense to have redirect creation without
420                  * redirect following.
421                  */
422                 config->redirect_follow = true;
423         } else if (strcmp(mode, "follow") == 0) {
424                 config->redirect_follow = true;
425         } else if (strcmp(mode, "off") == 0) {
426                 if (ovl_redirect_always_follow)
427                         config->redirect_follow = true;
428         } else if (strcmp(mode, "nofollow") != 0) {
429                 pr_err("overlayfs: bad mount option \"redirect_dir=%s\"\n",
430                        mode);
431                 return -EINVAL;
432         }
433 
434         return 0;
435 }
436 
437 static int ovl_parse_opt(char *opt, struct ovl_config *config)
438 {
439         char *p;
440 
441         config->redirect_mode = kstrdup(ovl_redirect_mode_def(), GFP_KERNEL);
442         if (!config->redirect_mode)
443                 return -ENOMEM;
444 
445         while ((p = ovl_next_opt(&opt)) != NULL) {
446                 int token;
447                 substring_t args[MAX_OPT_ARGS];
448 
449                 if (!*p)
450                         continue;
451 
452                 token = match_token(p, ovl_tokens, args);
453                 switch (token) {
454                 case OPT_UPPERDIR:
455                         kfree(config->upperdir);
456                         config->upperdir = match_strdup(&args[0]);
457                         if (!config->upperdir)
458                                 return -ENOMEM;
459                         break;
460 
461                 case OPT_LOWERDIR:
462                         kfree(config->lowerdir);
463                         config->lowerdir = match_strdup(&args[0]);
464                         if (!config->lowerdir)
465                                 return -ENOMEM;
466                         break;
467 
468                 case OPT_WORKDIR:
469                         kfree(config->workdir);
470                         config->workdir = match_strdup(&args[0]);
471                         if (!config->workdir)
472                                 return -ENOMEM;
473                         break;
474 
475                 case OPT_DEFAULT_PERMISSIONS:
476                         config->default_permissions = true;
477                         break;
478 
479                 case OPT_REDIRECT_DIR:
480                         kfree(config->redirect_mode);
481                         config->redirect_mode = match_strdup(&args[0]);
482                         if (!config->redirect_mode)
483                                 return -ENOMEM;
484                         break;
485 
486                 case OPT_INDEX_ON:
487                         config->index = true;
488                         break;
489 
490                 case OPT_INDEX_OFF:
491                         config->index = false;
492                         break;
493 
494                 default:
495                         pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
496                         return -EINVAL;
497                 }
498         }
499 
500         /* Workdir is useless in non-upper mount */
501         if (!config->upperdir && config->workdir) {
502                 pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
503                         config->workdir);
504                 kfree(config->workdir);
505                 config->workdir = NULL;
506         }
507 
508         return ovl_parse_redirect_mode(config, config->redirect_mode);
509 }
510 
511 #define OVL_WORKDIR_NAME "work"
512 #define OVL_INDEXDIR_NAME "index"
513 
514 static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
515                                          const char *name, bool persist)
516 {
517         struct inode *dir =  ofs->workbasedir->d_inode;
518         struct vfsmount *mnt = ofs->upper_mnt;
519         struct dentry *work;
520         int err;
521         bool retried = false;
522         bool locked = false;
523 
524         inode_lock_nested(dir, I_MUTEX_PARENT);
525         locked = true;
526 
527 retry:
528         work = lookup_one_len(name, ofs->workbasedir, strlen(name));
529 
530         if (!IS_ERR(work)) {
531                 struct iattr attr = {
532                         .ia_valid = ATTR_MODE,
533                         .ia_mode = S_IFDIR | 0,
534                 };
535 
536                 if (work->d_inode) {
537                         err = -EEXIST;
538                         if (retried)
539                                 goto out_dput;
540 
541                         if (persist)
542                                 goto out_unlock;
543 
544                         retried = true;
545                         ovl_workdir_cleanup(dir, mnt, work, 0);
546                         dput(work);
547                         goto retry;
548                 }
549 
550                 err = ovl_create_real(dir, work,
551                                       &(struct cattr){.mode = S_IFDIR | 0},
552                                       NULL, true);
553                 if (err)
554                         goto out_dput;
555 
556                 /*
557                  * Try to remove POSIX ACL xattrs from workdir.  We are good if:
558                  *
559                  * a) success (there was a POSIX ACL xattr and was removed)
560                  * b) -ENODATA (there was no POSIX ACL xattr)
561                  * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported)
562                  *
563                  * There are various other error values that could effectively
564                  * mean that the xattr doesn't exist (e.g. -ERANGE is returned
565                  * if the xattr name is too long), but the set of filesystems
566                  * allowed as upper are limited to "normal" ones, where checking
567                  * for the above two errors is sufficient.
568                  */
569                 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT);
570                 if (err && err != -ENODATA && err != -EOPNOTSUPP)
571                         goto out_dput;
572 
573                 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS);
574                 if (err && err != -ENODATA && err != -EOPNOTSUPP)
575                         goto out_dput;
576 
577                 /* Clear any inherited mode bits */
578                 inode_lock(work->d_inode);
579                 err = notify_change(work, &attr, NULL);
580                 inode_unlock(work->d_inode);
581                 if (err)
582                         goto out_dput;
583         } else {
584                 err = PTR_ERR(work);
585                 goto out_err;
586         }
587 out_unlock:
588         if (locked)
589                 inode_unlock(dir);
590 
591         return work;
592 
593 out_dput:
594         dput(work);
595 out_err:
596         pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n",
597                 ofs->config.workdir, name, -err);
598         work = NULL;
599         goto out_unlock;
600 }
601 
602 static void ovl_unescape(char *s)
603 {
604         char *d = s;
605 
606         for (;; s++, d++) {
607                 if (*s == '\\')
608                         s++;
609                 *d = *s;
610                 if (!*s)
611                         break;
612         }
613 }
614 
615 static int ovl_mount_dir_noesc(const char *name, struct path *path)
616 {
617         int err = -EINVAL;
618 
619         if (!*name) {
620                 pr_err("overlayfs: empty lowerdir\n");
621                 goto out;
622         }
623         err = kern_path(name, LOOKUP_FOLLOW, path);
624         if (err) {
625                 pr_err("overlayfs: failed to resolve '%s': %i\n", name, err);
626                 goto out;
627         }
628         err = -EINVAL;
629         if (ovl_dentry_weird(path->dentry)) {
630                 pr_err("overlayfs: filesystem on '%s' not supported\n", name);
631                 goto out_put;
632         }
633         if (!d_is_dir(path->dentry)) {
634                 pr_err("overlayfs: '%s' not a directory\n", name);
635                 goto out_put;
636         }
637         return 0;
638 
639 out_put:
640         path_put_init(path);
641 out:
642         return err;
643 }
644 
645 static int ovl_mount_dir(const char *name, struct path *path)
646 {
647         int err = -ENOMEM;
648         char *tmp = kstrdup(name, GFP_KERNEL);
649 
650         if (tmp) {
651                 ovl_unescape(tmp);
652                 err = ovl_mount_dir_noesc(tmp, path);
653 
654                 if (!err)
655                         if (ovl_dentry_remote(path->dentry)) {
656                                 pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n",
657                                        tmp);
658                                 path_put_init(path);
659                                 err = -EINVAL;
660                         }
661                 kfree(tmp);
662         }
663         return err;
664 }
665 
666 static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs,
667                              const char *name)
668 {
669         struct kstatfs statfs;
670         int err = vfs_statfs(path, &statfs);
671 
672         if (err)
673                 pr_err("overlayfs: statfs failed on '%s'\n", name);
674         else
675                 ofs->namelen = max(ofs->namelen, statfs.f_namelen);
676 
677         return err;
678 }
679 
680 static int ovl_lower_dir(const char *name, struct path *path,
681                          struct ovl_fs *ofs, int *stack_depth, bool *remote)
682 {
683         int err;
684 
685         err = ovl_mount_dir_noesc(name, path);
686         if (err)
687                 goto out;
688 
689         err = ovl_check_namelen(path, ofs, name);
690         if (err)
691                 goto out_put;
692 
693         *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth);
694 
695         if (ovl_dentry_remote(path->dentry))
696                 *remote = true;
697 
698         /*
699          * The inodes index feature needs to encode and decode file
700          * handles, so it requires that all layers support them.
701          */
702         if (ofs->config.index && ofs->config.upperdir &&
703             !ovl_can_decode_fh(path->dentry->d_sb)) {
704                 ofs->config.index = false;
705                 pr_warn("overlayfs: fs on '%s' does not support file handles, falling back to index=off.\n", name);
706         }
707 
708         return 0;
709 
710 out_put:
711         path_put_init(path);
712 out:
713         return err;
714 }
715 
716 /* Workdir should not be subdir of upperdir and vice versa */
717 static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
718 {
719         bool ok = false;
720 
721         if (workdir != upperdir) {
722                 ok = (lock_rename(workdir, upperdir) == NULL);
723                 unlock_rename(workdir, upperdir);
724         }
725         return ok;
726 }
727 
728 static unsigned int ovl_split_lowerdirs(char *str)
729 {
730         unsigned int ctr = 1;
731         char *s, *d;
732 
733         for (s = d = str;; s++, d++) {
734                 if (*s == '\\') {
735                         s++;
736                 } else if (*s == ':') {
737                         *d = '\0';
738                         ctr++;
739                         continue;
740                 }
741                 *d = *s;
742                 if (!*s)
743                         break;
744         }
745         return ctr;
746 }
747 
748 static int __maybe_unused
749 ovl_posix_acl_xattr_get(const struct xattr_handler *handler,
750                         struct dentry *dentry, struct inode *inode,
751                         const char *name, void *buffer, size_t size)
752 {
753         return ovl_xattr_get(dentry, inode, handler->name, buffer, size);
754 }
755 
756 static int __maybe_unused
757 ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
758                         struct dentry *dentry, struct inode *inode,
759                         const char *name, const void *value,
760                         size_t size, int flags)
761 {
762         struct dentry *workdir = ovl_workdir(dentry);
763         struct inode *realinode = ovl_inode_real(inode);
764         struct posix_acl *acl = NULL;
765         int err;
766 
767         /* Check that everything is OK before copy-up */
768         if (value) {
769                 acl = posix_acl_from_xattr(&init_user_ns, value, size);
770                 if (IS_ERR(acl))
771                         return PTR_ERR(acl);
772         }
773         err = -EOPNOTSUPP;
774         if (!IS_POSIXACL(d_inode(workdir)))
775                 goto out_acl_release;
776         if (!realinode->i_op->set_acl)
777                 goto out_acl_release;
778         if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) {
779                 err = acl ? -EACCES : 0;
780                 goto out_acl_release;
781         }
782         err = -EPERM;
783         if (!inode_owner_or_capable(inode))
784                 goto out_acl_release;
785 
786         posix_acl_release(acl);
787 
788         /*
789          * Check if sgid bit needs to be cleared (actual setacl operation will
790          * be done with mounter's capabilities and so that won't do it for us).
791          */
792         if (unlikely(inode->i_mode & S_ISGID) &&
793             handler->flags == ACL_TYPE_ACCESS &&
794             !in_group_p(inode->i_gid) &&
795             !capable_wrt_inode_uidgid(inode, CAP_FSETID)) {
796                 struct iattr iattr = { .ia_valid = ATTR_KILL_SGID };
797 
798                 err = ovl_setattr(dentry, &iattr);
799                 if (err)
800                         return err;
801         }
802 
803         err = ovl_xattr_set(dentry, inode, handler->name, value, size, flags);
804         if (!err)
805                 ovl_copyattr(ovl_inode_real(inode), inode);
806 
807         return err;
808 
809 out_acl_release:
810         posix_acl_release(acl);
811         return err;
812 }
813 
814 static int ovl_own_xattr_get(const struct xattr_handler *handler,
815                              struct dentry *dentry, struct inode *inode,
816                              const char *name, void *buffer, size_t size)
817 {
818         return -EOPNOTSUPP;
819 }
820 
821 static int ovl_own_xattr_set(const struct xattr_handler *handler,
822                              struct dentry *dentry, struct inode *inode,
823                              const char *name, const void *value,
824                              size_t size, int flags)
825 {
826         return -EOPNOTSUPP;
827 }
828 
829 static int ovl_other_xattr_get(const struct xattr_handler *handler,
830                                struct dentry *dentry, struct inode *inode,
831                                const char *name, void *buffer, size_t size)
832 {
833         return ovl_xattr_get(dentry, inode, name, buffer, size);
834 }
835 
836 static int ovl_other_xattr_set(const struct xattr_handler *handler,
837                                struct dentry *dentry, struct inode *inode,
838                                const char *name, const void *value,
839                                size_t size, int flags)
840 {
841         return ovl_xattr_set(dentry, inode, name, value, size, flags);
842 }
843 
844 static const struct xattr_handler __maybe_unused
845 ovl_posix_acl_access_xattr_handler = {
846         .name = XATTR_NAME_POSIX_ACL_ACCESS,
847         .flags = ACL_TYPE_ACCESS,
848         .get = ovl_posix_acl_xattr_get,
849         .set = ovl_posix_acl_xattr_set,
850 };
851 
852 static const struct xattr_handler __maybe_unused
853 ovl_posix_acl_default_xattr_handler = {
854         .name = XATTR_NAME_POSIX_ACL_DEFAULT,
855         .flags = ACL_TYPE_DEFAULT,
856         .get = ovl_posix_acl_xattr_get,
857         .set = ovl_posix_acl_xattr_set,
858 };
859 
860 static const struct xattr_handler ovl_own_xattr_handler = {
861         .prefix = OVL_XATTR_PREFIX,
862         .get = ovl_own_xattr_get,
863         .set = ovl_own_xattr_set,
864 };
865 
866 static const struct xattr_handler ovl_other_xattr_handler = {
867         .prefix = "", /* catch all */
868         .get = ovl_other_xattr_get,
869         .set = ovl_other_xattr_set,
870 };
871 
872 static const struct xattr_handler *ovl_xattr_handlers[] = {
873 #ifdef CONFIG_FS_POSIX_ACL
874         &ovl_posix_acl_access_xattr_handler,
875         &ovl_posix_acl_default_xattr_handler,
876 #endif
877         &ovl_own_xattr_handler,
878         &ovl_other_xattr_handler,
879         NULL
880 };
881 
882 static int ovl_get_upper(struct ovl_fs *ofs, struct path *upperpath)
883 {
884         struct vfsmount *upper_mnt;
885         int err;
886 
887         err = ovl_mount_dir(ofs->config.upperdir, upperpath);
888         if (err)
889                 goto out;
890 
891         /* Upper fs should not be r/o */
892         if (sb_rdonly(upperpath->mnt->mnt_sb)) {
893                 pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n");
894                 err = -EINVAL;
895                 goto out;
896         }
897 
898         err = ovl_check_namelen(upperpath, ofs, ofs->config.upperdir);
899         if (err)
900                 goto out;
901 
902         err = -EBUSY;
903         if (ovl_inuse_trylock(upperpath->dentry)) {
904                 ofs->upperdir_locked = true;
905         } else if (ofs->config.index) {
906                 pr_err("overlayfs: upperdir is in-use by another mount, mount with '-o index=off' to override exclusive upperdir protection.\n");
907                 goto out;
908         } else {
909                 pr_warn("overlayfs: upperdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n");
910         }
911 
912         upper_mnt = clone_private_mount(upperpath);
913         err = PTR_ERR(upper_mnt);
914         if (IS_ERR(upper_mnt)) {
915                 pr_err("overlayfs: failed to clone upperpath\n");
916                 goto out;
917         }
918 
919         /* Don't inherit atime flags */
920         upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME);
921         ofs->upper_mnt = upper_mnt;
922         err = 0;
923 out:
924         return err;
925 }
926 
927 static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath)
928 {
929         struct vfsmount *mnt = ofs->upper_mnt;
930         struct dentry *temp;
931         int err;
932 
933         err = mnt_want_write(mnt);
934         if (err)
935                 return err;
936 
937         ofs->workdir = ovl_workdir_create(ofs, OVL_WORKDIR_NAME, false);
938         if (!ofs->workdir)
939                 goto out;
940 
941         /*
942          * Upper should support d_type, else whiteouts are visible.  Given
943          * workdir and upper are on same fs, we can do iterate_dir() on
944          * workdir. This check requires successful creation of workdir in
945          * previous step.
946          */
947         err = ovl_check_d_type_supported(workpath);
948         if (err < 0)
949                 goto out;
950 
951         /*
952          * We allowed this configuration and don't want to break users over
953          * kernel upgrade. So warn instead of erroring out.
954          */
955         if (!err)
956                 pr_warn("overlayfs: upper fs needs to support d_type.\n");
957 
958         /* Check if upper/work fs supports O_TMPFILE */
959         temp = ovl_do_tmpfile(ofs->workdir, S_IFREG | 0);
960         ofs->tmpfile = !IS_ERR(temp);
961         if (ofs->tmpfile)
962                 dput(temp);
963         else
964                 pr_warn("overlayfs: upper fs does not support tmpfile.\n");
965 
966         /*
967          * Check if upper/work fs supports trusted.overlay.* xattr
968          */
969         err = ovl_do_setxattr(ofs->workdir, OVL_XATTR_OPAQUE, "", 1, 0);
970         if (err) {
971                 ofs->noxattr = true;
972                 pr_warn("overlayfs: upper fs does not support xattr.\n");
973                 err = 0;
974         } else {
975                 vfs_removexattr(ofs->workdir, OVL_XATTR_OPAQUE);
976         }
977 
978         /* Check if upper/work fs supports file handles */
979         if (ofs->config.index &&
980             !ovl_can_decode_fh(ofs->workdir->d_sb)) {
981                 ofs->config.index = false;
982                 pr_warn("overlayfs: upper fs does not support file handles, falling back to index=off.\n");
983         }
984 
985 out:
986         mnt_drop_write(mnt);
987         return err;
988 }
989 
990 static int ovl_get_workdir(struct ovl_fs *ofs, struct path *upperpath)
991 {
992         int err;
993         struct path workpath = { };
994 
995         err = ovl_mount_dir(ofs->config.workdir, &workpath);
996         if (err)
997                 goto out;
998 
999         err = -EINVAL;
1000         if (upperpath->mnt != workpath.mnt) {
1001                 pr_err("overlayfs: workdir and upperdir must reside under the same mount\n");
1002                 goto out;
1003         }
1004         if (!ovl_workdir_ok(workpath.dentry, upperpath->dentry)) {
1005                 pr_err("overlayfs: workdir and upperdir must be separate subtrees\n");
1006                 goto out;
1007         }
1008 
1009         err = -EBUSY;
1010         if (ovl_inuse_trylock(workpath.dentry)) {
1011                 ofs->workdir_locked = true;
1012         } else if (ofs->config.index) {
1013                 pr_err("overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.\n");
1014                 goto out;
1015         } else {
1016                 pr_warn("overlayfs: workdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n");
1017         }
1018 
1019         ofs->workbasedir = dget(workpath.dentry);
1020         err = ovl_make_workdir(ofs, &workpath);
1021         if (err)
1022                 goto out;
1023 
1024         err = 0;
1025 out:
1026         path_put(&workpath);
1027 
1028         return err;
1029 }
1030 
1031 static int ovl_get_indexdir(struct ovl_fs *ofs, struct ovl_entry *oe,
1032                             struct path *upperpath)
1033 {
1034         struct vfsmount *mnt = ofs->upper_mnt;
1035         int err;
1036 
1037         err = mnt_want_write(mnt);
1038         if (err)
1039                 return err;
1040 
1041         /* Verify lower root is upper root origin */
1042         err = ovl_verify_origin(upperpath->dentry, oe->lowerstack[0].dentry,
1043                                 false, true);
1044         if (err) {
1045                 pr_err("overlayfs: failed to verify upper root origin\n");
1046                 goto out;
1047         }
1048 
1049         ofs->indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true);
1050         if (ofs->indexdir) {
1051                 /* Verify upper root is index dir origin */
1052                 err = ovl_verify_origin(ofs->indexdir, upperpath->dentry,
1053                                         true, true);
1054                 if (err)
1055                         pr_err("overlayfs: failed to verify index dir origin\n");
1056 
1057                 /* Cleanup bad/stale/orphan index entries */
1058                 if (!err)
1059                         err = ovl_indexdir_cleanup(ofs->indexdir,
1060                                                    ofs->upper_mnt,
1061                                                    oe->lowerstack,
1062                                                    oe->numlower);
1063         }
1064         if (err || !ofs->indexdir)
1065                 pr_warn("overlayfs: try deleting index dir or mounting with '-o index=off' to disable inodes index.\n");
1066 
1067 out:
1068         mnt_drop_write(mnt);
1069         return err;
1070 }
1071 
1072 static int ovl_get_lower_layers(struct ovl_fs *ofs, struct path *stack,
1073                                 unsigned int numlower)
1074 {
1075         int err;
1076         unsigned int i;
1077 
1078         err = -ENOMEM;
1079         ofs->lower_layers = kcalloc(numlower, sizeof(struct ovl_layer),
1080                                     GFP_KERNEL);
1081         if (ofs->lower_layers == NULL)
1082                 goto out;
1083         for (i = 0; i < numlower; i++) {
1084                 struct vfsmount *mnt;
1085                 dev_t dev;
1086 
1087                 err = get_anon_bdev(&dev);
1088                 if (err) {
1089                         pr_err("overlayfs: failed to get anonymous bdev for lowerpath\n");
1090                         goto out;
1091                 }
1092 
1093                 mnt = clone_private_mount(&stack[i]);
1094                 err = PTR_ERR(mnt);
1095                 if (IS_ERR(mnt)) {
1096                         pr_err("overlayfs: failed to clone lowerpath\n");
1097                         free_anon_bdev(dev);
1098                         goto out;
1099                 }
1100                 /*
1101                  * Make lower layers R/O.  That way fchmod/fchown on lower file
1102                  * will fail instead of modifying lower fs.
1103                  */
1104                 mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME;
1105 
1106                 ofs->lower_layers[ofs->numlower].mnt = mnt;
1107                 ofs->lower_layers[ofs->numlower].pseudo_dev = dev;
1108                 ofs->numlower++;
1109 
1110                 /* Check if all lower layers are on same sb */
1111                 if (i == 0)
1112                         ofs->same_sb = mnt->mnt_sb;
1113                 else if (ofs->same_sb != mnt->mnt_sb)
1114                         ofs->same_sb = NULL;
1115         }
1116         err = 0;
1117 out:
1118         return err;
1119 }
1120 
1121 static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
1122                                             struct ovl_fs *ofs)
1123 {
1124         int err;
1125         char *lowertmp, *lower;
1126         struct path *stack = NULL;
1127         unsigned int stacklen, numlower = 0, i;
1128         bool remote = false;
1129         struct ovl_entry *oe;
1130 
1131         err = -ENOMEM;
1132         lowertmp = kstrdup(ofs->config.lowerdir, GFP_KERNEL);
1133         if (!lowertmp)
1134                 goto out_err;
1135 
1136         err = -EINVAL;
1137         stacklen = ovl_split_lowerdirs(lowertmp);
1138         if (stacklen > OVL_MAX_STACK) {
1139                 pr_err("overlayfs: too many lower directories, limit is %d\n",
1140                        OVL_MAX_STACK);
1141                 goto out_err;
1142         } else if (!ofs->config.upperdir && stacklen == 1) {
1143                 pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
1144                 goto out_err;
1145         }
1146 
1147         err = -ENOMEM;
1148         stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
1149         if (!stack)
1150                 goto out_err;
1151 
1152         err = -EINVAL;
1153         lower = lowertmp;
1154         for (numlower = 0; numlower < stacklen; numlower++) {
1155                 err = ovl_lower_dir(lower, &stack[numlower], ofs,
1156                                     &sb->s_stack_depth, &remote);
1157                 if (err)
1158                         goto out_err;
1159 
1160                 lower = strchr(lower, '\0') + 1;
1161         }
1162 
1163         err = -EINVAL;
1164         sb->s_stack_depth++;
1165         if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
1166                 pr_err("overlayfs: maximum fs stacking depth exceeded\n");
1167                 goto out_err;
1168         }
1169 
1170         err = ovl_get_lower_layers(ofs, stack, numlower);
1171         if (err)
1172                 goto out_err;
1173 
1174         err = -ENOMEM;
1175         oe = ovl_alloc_entry(numlower);
1176         if (!oe)
1177                 goto out_err;
1178 
1179         for (i = 0; i < numlower; i++) {
1180                 oe->lowerstack[i].dentry = dget(stack[i].dentry);
1181                 oe->lowerstack[i].layer = &ofs->lower_layers[i];
1182         }
1183 
1184         if (remote)
1185                 sb->s_d_op = &ovl_reval_dentry_operations;
1186         else
1187                 sb->s_d_op = &ovl_dentry_operations;
1188 
1189 out:
1190         for (i = 0; i < numlower; i++)
1191                 path_put(&stack[i]);
1192         kfree(stack);
1193         kfree(lowertmp);
1194 
1195         return oe;
1196 
1197 out_err:
1198         oe = ERR_PTR(err);
1199         goto out;
1200 }
1201 
1202 static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1203 {
1204         struct path upperpath = { };
1205         struct dentry *root_dentry;
1206         struct ovl_entry *oe;
1207         struct ovl_fs *ofs;
1208         struct cred *cred;
1209         int err;
1210 
1211         err = -ENOMEM;
1212         ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL);
1213         if (!ofs)
1214                 goto out;
1215 
1216         ofs->creator_cred = cred = prepare_creds();
1217         if (!cred)
1218                 goto out_err;
1219 
1220         ofs->config.index = ovl_index_def;
1221         err = ovl_parse_opt((char *) data, &ofs->config);
1222         if (err)
1223                 goto out_err;
1224 
1225         err = -EINVAL;
1226         if (!ofs->config.lowerdir) {
1227                 if (!silent)
1228                         pr_err("overlayfs: missing 'lowerdir'\n");
1229                 goto out_err;
1230         }
1231 
1232         sb->s_stack_depth = 0;
1233         sb->s_maxbytes = MAX_LFS_FILESIZE;
1234         if (ofs->config.upperdir) {
1235                 if (!ofs->config.workdir) {
1236                         pr_err("overlayfs: missing 'workdir'\n");
1237                         goto out_err;
1238                 }
1239 
1240                 err = ovl_get_upper(ofs, &upperpath);
1241                 if (err)
1242                         goto out_err;
1243 
1244                 err = ovl_get_workdir(ofs, &upperpath);
1245                 if (err)
1246                         goto out_err;
1247 
1248                 if (!ofs->workdir)
1249                         sb->s_flags |= SB_RDONLY;
1250 
1251                 sb->s_stack_depth = ofs->upper_mnt->mnt_sb->s_stack_depth;
1252                 sb->s_time_gran = ofs->upper_mnt->mnt_sb->s_time_gran;
1253 
1254         }
1255         oe = ovl_get_lowerstack(sb, ofs);
1256         err = PTR_ERR(oe);
1257         if (IS_ERR(oe))
1258                 goto out_err;
1259 
1260         /* If the upper fs is nonexistent, we mark overlayfs r/o too */
1261         if (!ofs->upper_mnt)
1262                 sb->s_flags |= SB_RDONLY;
1263         else if (ofs->upper_mnt->mnt_sb != ofs->same_sb)
1264                 ofs->same_sb = NULL;
1265 
1266         if (!(ovl_force_readonly(ofs)) && ofs->config.index) {
1267                 err = ovl_get_indexdir(ofs, oe, &upperpath);
1268                 if (err)
1269                         goto out_free_oe;
1270 
1271                 /* Force r/o mount with no index dir */
1272                 if (!ofs->indexdir) {
1273                         dput(ofs->workdir);
1274                         ofs->workdir = NULL;
1275                         sb->s_flags |= SB_RDONLY;
1276                 }
1277 
1278         }
1279 
1280         /* Show index=off in /proc/mounts for forced r/o mount */
1281         if (!ofs->indexdir)
1282                 ofs->config.index = false;
1283 
1284         /* Never override disk quota limits or use reserved space */
1285         cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
1286 
1287         sb->s_magic = OVERLAYFS_SUPER_MAGIC;
1288         sb->s_op = &ovl_super_operations;
1289         sb->s_xattr = ovl_xattr_handlers;
1290         sb->s_fs_info = ofs;
1291         sb->s_flags |= SB_POSIXACL | SB_NOREMOTELOCK;
1292 
1293         err = -ENOMEM;
1294         root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
1295         if (!root_dentry)
1296                 goto out_free_oe;
1297 
1298         mntput(upperpath.mnt);
1299         if (upperpath.dentry) {
1300                 oe->has_upper = true;
1301                 if (ovl_is_impuredir(upperpath.dentry))
1302                         ovl_set_flag(OVL_IMPURE, d_inode(root_dentry));
1303         }
1304 
1305         root_dentry->d_fsdata = oe;
1306 
1307         /* Root is always merge -> can have whiteouts */
1308         ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry));
1309         ovl_inode_init(d_inode(root_dentry), upperpath.dentry,
1310                        ovl_dentry_lower(root_dentry));
1311 
1312         sb->s_root = root_dentry;
1313 
1314         return 0;
1315 
1316 out_free_oe:
1317         ovl_entry_stack_free(oe);
1318         kfree(oe);
1319 out_err:
1320         path_put(&upperpath);
1321         ovl_free_fs(ofs);
1322 out:
1323         return err;
1324 }
1325 
1326 static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
1327                                 const char *dev_name, void *raw_data)
1328 {
1329         return mount_nodev(fs_type, flags, raw_data, ovl_fill_super);
1330 }
1331 
1332 static struct file_system_type ovl_fs_type = {
1333         .owner          = THIS_MODULE,
1334         .name           = "overlay",
1335         .mount          = ovl_mount,
1336         .kill_sb        = kill_anon_super,
1337 };
1338 MODULE_ALIAS_FS("overlay");
1339 
1340 static void ovl_inode_init_once(void *foo)
1341 {
1342         struct ovl_inode *oi = foo;
1343 
1344         inode_init_once(&oi->vfs_inode);
1345 }
1346 
1347 static int __init ovl_init(void)
1348 {
1349         int err;
1350 
1351         ovl_inode_cachep = kmem_cache_create("ovl_inode",
1352                                              sizeof(struct ovl_inode), 0,
1353                                              (SLAB_RECLAIM_ACCOUNT|
1354                                               SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1355                                              ovl_inode_init_once);
1356         if (ovl_inode_cachep == NULL)
1357                 return -ENOMEM;
1358 
1359         err = register_filesystem(&ovl_fs_type);
1360         if (err)
1361                 kmem_cache_destroy(ovl_inode_cachep);
1362 
1363         return err;
1364 }
1365 
1366 static void __exit ovl_exit(void)
1367 {
1368         unregister_filesystem(&ovl_fs_type);
1369 
1370         /*
1371          * Make sure all delayed rcu free inodes are flushed before we
1372          * destroy cache.
1373          */
1374         rcu_barrier();
1375         kmem_cache_destroy(ovl_inode_cachep);
1376 
1377 }
1378 
1379 module_init(ovl_init);
1380 module_exit(ovl_exit);
1381 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp