Back to home page

OSCL-LXR

 
 

    


0001 /* AFS superblock handling
0002  *
0003  * Copyright (c) 2002, 2007, 2018 Red Hat, Inc. All rights reserved.
0004  *
0005  * This software may be freely redistributed under the terms of the
0006  * GNU General Public License.
0007  *
0008  * You should have received a copy of the GNU General Public License
0009  * along with this program; if not, write to the Free Software
0010  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0011  *
0012  * Authors: David Howells <dhowells@redhat.com>
0013  *          David Woodhouse <dwmw2@infradead.org>
0014  *
0015  */
0016 
0017 #include <linux/kernel.h>
0018 #include <linux/module.h>
0019 #include <linux/mount.h>
0020 #include <linux/init.h>
0021 #include <linux/slab.h>
0022 #include <linux/fs.h>
0023 #include <linux/pagemap.h>
0024 #include <linux/fs_parser.h>
0025 #include <linux/statfs.h>
0026 #include <linux/sched.h>
0027 #include <linux/nsproxy.h>
0028 #include <linux/magic.h>
0029 #include <net/net_namespace.h>
0030 #include "internal.h"
0031 
0032 static void afs_i_init_once(void *foo);
0033 static void afs_kill_super(struct super_block *sb);
0034 static struct inode *afs_alloc_inode(struct super_block *sb);
0035 static void afs_destroy_inode(struct inode *inode);
0036 static void afs_free_inode(struct inode *inode);
0037 static int afs_statfs(struct dentry *dentry, struct kstatfs *buf);
0038 static int afs_show_devname(struct seq_file *m, struct dentry *root);
0039 static int afs_show_options(struct seq_file *m, struct dentry *root);
0040 static int afs_init_fs_context(struct fs_context *fc);
0041 static const struct fs_parameter_spec afs_fs_parameters[];
0042 
0043 struct file_system_type afs_fs_type = {
0044     .owner          = THIS_MODULE,
0045     .name           = "afs",
0046     .init_fs_context    = afs_init_fs_context,
0047     .parameters     = afs_fs_parameters,
0048     .kill_sb        = afs_kill_super,
0049     .fs_flags       = FS_RENAME_DOES_D_MOVE,
0050 };
0051 MODULE_ALIAS_FS("afs");
0052 
0053 int afs_net_id;
0054 
0055 static const struct super_operations afs_super_ops = {
0056     .statfs     = afs_statfs,
0057     .alloc_inode    = afs_alloc_inode,
0058     .write_inode    = afs_write_inode,
0059     .drop_inode = afs_drop_inode,
0060     .destroy_inode  = afs_destroy_inode,
0061     .free_inode = afs_free_inode,
0062     .evict_inode    = afs_evict_inode,
0063     .show_devname   = afs_show_devname,
0064     .show_options   = afs_show_options,
0065 };
0066 
0067 static struct kmem_cache *afs_inode_cachep;
0068 static atomic_t afs_count_active_inodes;
0069 
0070 enum afs_param {
0071     Opt_autocell,
0072     Opt_dyn,
0073     Opt_flock,
0074     Opt_source,
0075 };
0076 
0077 static const struct constant_table afs_param_flock[] = {
0078     {"local",   afs_flock_mode_local },
0079     {"openafs", afs_flock_mode_openafs },
0080     {"strict",  afs_flock_mode_strict },
0081     {"write",   afs_flock_mode_write },
0082     {}
0083 };
0084 
0085 static const struct fs_parameter_spec afs_fs_parameters[] = {
0086     fsparam_flag  ("autocell",  Opt_autocell),
0087     fsparam_flag  ("dyn",       Opt_dyn),
0088     fsparam_enum  ("flock",     Opt_flock, afs_param_flock),
0089     fsparam_string("source",    Opt_source),
0090     {}
0091 };
0092 
0093 /*
0094  * initialise the filesystem
0095  */
0096 int __init afs_fs_init(void)
0097 {
0098     int ret;
0099 
0100     _enter("");
0101 
0102     /* create ourselves an inode cache */
0103     atomic_set(&afs_count_active_inodes, 0);
0104 
0105     ret = -ENOMEM;
0106     afs_inode_cachep = kmem_cache_create("afs_inode_cache",
0107                          sizeof(struct afs_vnode),
0108                          0,
0109                          SLAB_HWCACHE_ALIGN|SLAB_ACCOUNT,
0110                          afs_i_init_once);
0111     if (!afs_inode_cachep) {
0112         printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
0113         return ret;
0114     }
0115 
0116     /* now export our filesystem to lesser mortals */
0117     ret = register_filesystem(&afs_fs_type);
0118     if (ret < 0) {
0119         kmem_cache_destroy(afs_inode_cachep);
0120         _leave(" = %d", ret);
0121         return ret;
0122     }
0123 
0124     _leave(" = 0");
0125     return 0;
0126 }
0127 
0128 /*
0129  * clean up the filesystem
0130  */
0131 void afs_fs_exit(void)
0132 {
0133     _enter("");
0134 
0135     afs_mntpt_kill_timer();
0136     unregister_filesystem(&afs_fs_type);
0137 
0138     if (atomic_read(&afs_count_active_inodes) != 0) {
0139         printk("kAFS: %d active inode objects still present\n",
0140                atomic_read(&afs_count_active_inodes));
0141         BUG();
0142     }
0143 
0144     /*
0145      * Make sure all delayed rcu free inodes are flushed before we
0146      * destroy cache.
0147      */
0148     rcu_barrier();
0149     kmem_cache_destroy(afs_inode_cachep);
0150     _leave("");
0151 }
0152 
0153 /*
0154  * Display the mount device name in /proc/mounts.
0155  */
0156 static int afs_show_devname(struct seq_file *m, struct dentry *root)
0157 {
0158     struct afs_super_info *as = AFS_FS_S(root->d_sb);
0159     struct afs_volume *volume = as->volume;
0160     struct afs_cell *cell = as->cell;
0161     const char *suf = "";
0162     char pref = '%';
0163 
0164     if (as->dyn_root) {
0165         seq_puts(m, "none");
0166         return 0;
0167     }
0168 
0169     switch (volume->type) {
0170     case AFSVL_RWVOL:
0171         break;
0172     case AFSVL_ROVOL:
0173         pref = '#';
0174         if (volume->type_force)
0175             suf = ".readonly";
0176         break;
0177     case AFSVL_BACKVOL:
0178         pref = '#';
0179         suf = ".backup";
0180         break;
0181     }
0182 
0183     seq_printf(m, "%c%s:%s%s", pref, cell->name, volume->name, suf);
0184     return 0;
0185 }
0186 
0187 /*
0188  * Display the mount options in /proc/mounts.
0189  */
0190 static int afs_show_options(struct seq_file *m, struct dentry *root)
0191 {
0192     struct afs_super_info *as = AFS_FS_S(root->d_sb);
0193     const char *p = NULL;
0194 
0195     if (as->dyn_root)
0196         seq_puts(m, ",dyn");
0197     if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(d_inode(root))->flags))
0198         seq_puts(m, ",autocell");
0199     switch (as->flock_mode) {
0200     case afs_flock_mode_unset:  break;
0201     case afs_flock_mode_local:  p = "local";    break;
0202     case afs_flock_mode_openafs:    p = "openafs";  break;
0203     case afs_flock_mode_strict: p = "strict";   break;
0204     case afs_flock_mode_write:  p = "write";    break;
0205     }
0206     if (p)
0207         seq_printf(m, ",flock=%s", p);
0208 
0209     return 0;
0210 }
0211 
0212 /*
0213  * Parse the source name to get cell name, volume name, volume type and R/W
0214  * selector.
0215  *
0216  * This can be one of the following:
0217  *  "%[cell:]volume[.]"     R/W volume
0218  *  "#[cell:]volume[.]"     R/O or R/W volume (R/O parent),
0219  *                   or R/W (R/W parent) volume
0220  *  "%[cell:]volume.readonly"   R/O volume
0221  *  "#[cell:]volume.readonly"   R/O volume
0222  *  "%[cell:]volume.backup"     Backup volume
0223  *  "#[cell:]volume.backup"     Backup volume
0224  */
0225 static int afs_parse_source(struct fs_context *fc, struct fs_parameter *param)
0226 {
0227     struct afs_fs_context *ctx = fc->fs_private;
0228     struct afs_cell *cell;
0229     const char *cellname, *suffix, *name = param->string;
0230     int cellnamesz;
0231 
0232     _enter(",%s", name);
0233 
0234     if (fc->source)
0235         return invalf(fc, "kAFS: Multiple sources not supported");
0236 
0237     if (!name) {
0238         printk(KERN_ERR "kAFS: no volume name specified\n");
0239         return -EINVAL;
0240     }
0241 
0242     if ((name[0] != '%' && name[0] != '#') || !name[1]) {
0243         /* To use dynroot, we don't want to have to provide a source */
0244         if (strcmp(name, "none") == 0) {
0245             ctx->no_cell = true;
0246             return 0;
0247         }
0248         printk(KERN_ERR "kAFS: unparsable volume name\n");
0249         return -EINVAL;
0250     }
0251 
0252     /* determine the type of volume we're looking for */
0253     if (name[0] == '%') {
0254         ctx->type = AFSVL_RWVOL;
0255         ctx->force = true;
0256     }
0257     name++;
0258 
0259     /* split the cell name out if there is one */
0260     ctx->volname = strchr(name, ':');
0261     if (ctx->volname) {
0262         cellname = name;
0263         cellnamesz = ctx->volname - name;
0264         ctx->volname++;
0265     } else {
0266         ctx->volname = name;
0267         cellname = NULL;
0268         cellnamesz = 0;
0269     }
0270 
0271     /* the volume type is further affected by a possible suffix */
0272     suffix = strrchr(ctx->volname, '.');
0273     if (suffix) {
0274         if (strcmp(suffix, ".readonly") == 0) {
0275             ctx->type = AFSVL_ROVOL;
0276             ctx->force = true;
0277         } else if (strcmp(suffix, ".backup") == 0) {
0278             ctx->type = AFSVL_BACKVOL;
0279             ctx->force = true;
0280         } else if (suffix[1] == 0) {
0281         } else {
0282             suffix = NULL;
0283         }
0284     }
0285 
0286     ctx->volnamesz = suffix ?
0287         suffix - ctx->volname : strlen(ctx->volname);
0288 
0289     _debug("cell %*.*s [%p]",
0290            cellnamesz, cellnamesz, cellname ?: "", ctx->cell);
0291 
0292     /* lookup the cell record */
0293     if (cellname) {
0294         cell = afs_lookup_cell(ctx->net, cellname, cellnamesz,
0295                        NULL, false);
0296         if (IS_ERR(cell)) {
0297             pr_err("kAFS: unable to lookup cell '%*.*s'\n",
0298                    cellnamesz, cellnamesz, cellname ?: "");
0299             return PTR_ERR(cell);
0300         }
0301         afs_unuse_cell(ctx->net, ctx->cell, afs_cell_trace_unuse_parse);
0302         afs_see_cell(cell, afs_cell_trace_see_source);
0303         ctx->cell = cell;
0304     }
0305 
0306     _debug("CELL:%s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
0307            ctx->cell->name, ctx->cell,
0308            ctx->volnamesz, ctx->volnamesz, ctx->volname,
0309            suffix ?: "-", ctx->type, ctx->force ? " FORCE" : "");
0310 
0311     fc->source = param->string;
0312     param->string = NULL;
0313     return 0;
0314 }
0315 
0316 /*
0317  * Parse a single mount parameter.
0318  */
0319 static int afs_parse_param(struct fs_context *fc, struct fs_parameter *param)
0320 {
0321     struct fs_parse_result result;
0322     struct afs_fs_context *ctx = fc->fs_private;
0323     int opt;
0324 
0325     opt = fs_parse(fc, afs_fs_parameters, param, &result);
0326     if (opt < 0)
0327         return opt;
0328 
0329     switch (opt) {
0330     case Opt_source:
0331         return afs_parse_source(fc, param);
0332 
0333     case Opt_autocell:
0334         ctx->autocell = true;
0335         break;
0336 
0337     case Opt_dyn:
0338         ctx->dyn_root = true;
0339         break;
0340 
0341     case Opt_flock:
0342         ctx->flock_mode = result.uint_32;
0343         break;
0344 
0345     default:
0346         return -EINVAL;
0347     }
0348 
0349     _leave(" = 0");
0350     return 0;
0351 }
0352 
0353 /*
0354  * Validate the options, get the cell key and look up the volume.
0355  */
0356 static int afs_validate_fc(struct fs_context *fc)
0357 {
0358     struct afs_fs_context *ctx = fc->fs_private;
0359     struct afs_volume *volume;
0360     struct afs_cell *cell;
0361     struct key *key;
0362     int ret;
0363 
0364     if (!ctx->dyn_root) {
0365         if (ctx->no_cell) {
0366             pr_warn("kAFS: Can only specify source 'none' with -o dyn\n");
0367             return -EINVAL;
0368         }
0369 
0370         if (!ctx->cell) {
0371             pr_warn("kAFS: No cell specified\n");
0372             return -EDESTADDRREQ;
0373         }
0374 
0375     reget_key:
0376         /* We try to do the mount securely. */
0377         key = afs_request_key(ctx->cell);
0378         if (IS_ERR(key))
0379             return PTR_ERR(key);
0380 
0381         ctx->key = key;
0382 
0383         if (ctx->volume) {
0384             afs_put_volume(ctx->net, ctx->volume,
0385                        afs_volume_trace_put_validate_fc);
0386             ctx->volume = NULL;
0387         }
0388 
0389         if (test_bit(AFS_CELL_FL_CHECK_ALIAS, &ctx->cell->flags)) {
0390             ret = afs_cell_detect_alias(ctx->cell, key);
0391             if (ret < 0)
0392                 return ret;
0393             if (ret == 1) {
0394                 _debug("switch to alias");
0395                 key_put(ctx->key);
0396                 ctx->key = NULL;
0397                 cell = afs_use_cell(ctx->cell->alias_of,
0398                             afs_cell_trace_use_fc_alias);
0399                 afs_unuse_cell(ctx->net, ctx->cell, afs_cell_trace_unuse_fc);
0400                 ctx->cell = cell;
0401                 goto reget_key;
0402             }
0403         }
0404 
0405         volume = afs_create_volume(ctx);
0406         if (IS_ERR(volume))
0407             return PTR_ERR(volume);
0408 
0409         ctx->volume = volume;
0410     }
0411 
0412     return 0;
0413 }
0414 
0415 /*
0416  * check a superblock to see if it's the one we're looking for
0417  */
0418 static int afs_test_super(struct super_block *sb, struct fs_context *fc)
0419 {
0420     struct afs_fs_context *ctx = fc->fs_private;
0421     struct afs_super_info *as = AFS_FS_S(sb);
0422 
0423     return (as->net_ns == fc->net_ns &&
0424         as->volume &&
0425         as->volume->vid == ctx->volume->vid &&
0426         as->cell == ctx->cell &&
0427         !as->dyn_root);
0428 }
0429 
0430 static int afs_dynroot_test_super(struct super_block *sb, struct fs_context *fc)
0431 {
0432     struct afs_super_info *as = AFS_FS_S(sb);
0433 
0434     return (as->net_ns == fc->net_ns &&
0435         as->dyn_root);
0436 }
0437 
0438 static int afs_set_super(struct super_block *sb, struct fs_context *fc)
0439 {
0440     return set_anon_super(sb, NULL);
0441 }
0442 
0443 /*
0444  * fill in the superblock
0445  */
0446 static int afs_fill_super(struct super_block *sb, struct afs_fs_context *ctx)
0447 {
0448     struct afs_super_info *as = AFS_FS_S(sb);
0449     struct inode *inode = NULL;
0450     int ret;
0451 
0452     _enter("");
0453 
0454     /* fill in the superblock */
0455     sb->s_blocksize     = PAGE_SIZE;
0456     sb->s_blocksize_bits    = PAGE_SHIFT;
0457     sb->s_maxbytes      = MAX_LFS_FILESIZE;
0458     sb->s_magic     = AFS_FS_MAGIC;
0459     sb->s_op        = &afs_super_ops;
0460     if (!as->dyn_root)
0461         sb->s_xattr = afs_xattr_handlers;
0462     ret = super_setup_bdi(sb);
0463     if (ret)
0464         return ret;
0465 
0466     /* allocate the root inode and dentry */
0467     if (as->dyn_root) {
0468         inode = afs_iget_pseudo_dir(sb, true);
0469     } else {
0470         sprintf(sb->s_id, "%llu", as->volume->vid);
0471         afs_activate_volume(as->volume);
0472         inode = afs_root_iget(sb, ctx->key);
0473     }
0474 
0475     if (IS_ERR(inode))
0476         return PTR_ERR(inode);
0477 
0478     if (ctx->autocell || as->dyn_root)
0479         set_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags);
0480 
0481     ret = -ENOMEM;
0482     sb->s_root = d_make_root(inode);
0483     if (!sb->s_root)
0484         goto error;
0485 
0486     if (as->dyn_root) {
0487         sb->s_d_op = &afs_dynroot_dentry_operations;
0488         ret = afs_dynroot_populate(sb);
0489         if (ret < 0)
0490             goto error;
0491     } else {
0492         sb->s_d_op = &afs_fs_dentry_operations;
0493         rcu_assign_pointer(as->volume->sb, sb);
0494     }
0495 
0496     _leave(" = 0");
0497     return 0;
0498 
0499 error:
0500     _leave(" = %d", ret);
0501     return ret;
0502 }
0503 
0504 static struct afs_super_info *afs_alloc_sbi(struct fs_context *fc)
0505 {
0506     struct afs_fs_context *ctx = fc->fs_private;
0507     struct afs_super_info *as;
0508 
0509     as = kzalloc(sizeof(struct afs_super_info), GFP_KERNEL);
0510     if (as) {
0511         as->net_ns = get_net(fc->net_ns);
0512         as->flock_mode = ctx->flock_mode;
0513         if (ctx->dyn_root) {
0514             as->dyn_root = true;
0515         } else {
0516             as->cell = afs_use_cell(ctx->cell, afs_cell_trace_use_sbi);
0517             as->volume = afs_get_volume(ctx->volume,
0518                             afs_volume_trace_get_alloc_sbi);
0519         }
0520     }
0521     return as;
0522 }
0523 
0524 static void afs_destroy_sbi(struct afs_super_info *as)
0525 {
0526     if (as) {
0527         struct afs_net *net = afs_net(as->net_ns);
0528         afs_put_volume(net, as->volume, afs_volume_trace_put_destroy_sbi);
0529         afs_unuse_cell(net, as->cell, afs_cell_trace_unuse_sbi);
0530         put_net(as->net_ns);
0531         kfree(as);
0532     }
0533 }
0534 
0535 static void afs_kill_super(struct super_block *sb)
0536 {
0537     struct afs_super_info *as = AFS_FS_S(sb);
0538 
0539     if (as->dyn_root)
0540         afs_dynroot_depopulate(sb);
0541 
0542     /* Clear the callback interests (which will do ilookup5) before
0543      * deactivating the superblock.
0544      */
0545     if (as->volume)
0546         rcu_assign_pointer(as->volume->sb, NULL);
0547     kill_anon_super(sb);
0548     if (as->volume)
0549         afs_deactivate_volume(as->volume);
0550     afs_destroy_sbi(as);
0551 }
0552 
0553 /*
0554  * Get an AFS superblock and root directory.
0555  */
0556 static int afs_get_tree(struct fs_context *fc)
0557 {
0558     struct afs_fs_context *ctx = fc->fs_private;
0559     struct super_block *sb;
0560     struct afs_super_info *as;
0561     int ret;
0562 
0563     ret = afs_validate_fc(fc);
0564     if (ret)
0565         goto error;
0566 
0567     _enter("");
0568 
0569     /* allocate a superblock info record */
0570     ret = -ENOMEM;
0571     as = afs_alloc_sbi(fc);
0572     if (!as)
0573         goto error;
0574     fc->s_fs_info = as;
0575 
0576     /* allocate a deviceless superblock */
0577     sb = sget_fc(fc,
0578              as->dyn_root ? afs_dynroot_test_super : afs_test_super,
0579              afs_set_super);
0580     if (IS_ERR(sb)) {
0581         ret = PTR_ERR(sb);
0582         goto error;
0583     }
0584 
0585     if (!sb->s_root) {
0586         /* initial superblock/root creation */
0587         _debug("create");
0588         ret = afs_fill_super(sb, ctx);
0589         if (ret < 0)
0590             goto error_sb;
0591         sb->s_flags |= SB_ACTIVE;
0592     } else {
0593         _debug("reuse");
0594         ASSERTCMP(sb->s_flags, &, SB_ACTIVE);
0595     }
0596 
0597     fc->root = dget(sb->s_root);
0598     trace_afs_get_tree(as->cell, as->volume);
0599     _leave(" = 0 [%p]", sb);
0600     return 0;
0601 
0602 error_sb:
0603     deactivate_locked_super(sb);
0604 error:
0605     _leave(" = %d", ret);
0606     return ret;
0607 }
0608 
0609 static void afs_free_fc(struct fs_context *fc)
0610 {
0611     struct afs_fs_context *ctx = fc->fs_private;
0612 
0613     afs_destroy_sbi(fc->s_fs_info);
0614     afs_put_volume(ctx->net, ctx->volume, afs_volume_trace_put_free_fc);
0615     afs_unuse_cell(ctx->net, ctx->cell, afs_cell_trace_unuse_fc);
0616     key_put(ctx->key);
0617     kfree(ctx);
0618 }
0619 
0620 static const struct fs_context_operations afs_context_ops = {
0621     .free       = afs_free_fc,
0622     .parse_param    = afs_parse_param,
0623     .get_tree   = afs_get_tree,
0624 };
0625 
0626 /*
0627  * Set up the filesystem mount context.
0628  */
0629 static int afs_init_fs_context(struct fs_context *fc)
0630 {
0631     struct afs_fs_context *ctx;
0632     struct afs_cell *cell;
0633 
0634     ctx = kzalloc(sizeof(struct afs_fs_context), GFP_KERNEL);
0635     if (!ctx)
0636         return -ENOMEM;
0637 
0638     ctx->type = AFSVL_ROVOL;
0639     ctx->net = afs_net(fc->net_ns);
0640 
0641     /* Default to the workstation cell. */
0642     cell = afs_find_cell(ctx->net, NULL, 0, afs_cell_trace_use_fc);
0643     if (IS_ERR(cell))
0644         cell = NULL;
0645     ctx->cell = cell;
0646 
0647     fc->fs_private = ctx;
0648     fc->ops = &afs_context_ops;
0649     return 0;
0650 }
0651 
0652 /*
0653  * Initialise an inode cache slab element prior to any use.  Note that
0654  * afs_alloc_inode() *must* reset anything that could incorrectly leak from one
0655  * inode to another.
0656  */
0657 static void afs_i_init_once(void *_vnode)
0658 {
0659     struct afs_vnode *vnode = _vnode;
0660 
0661     memset(vnode, 0, sizeof(*vnode));
0662     inode_init_once(&vnode->netfs.inode);
0663     mutex_init(&vnode->io_lock);
0664     init_rwsem(&vnode->validate_lock);
0665     spin_lock_init(&vnode->wb_lock);
0666     spin_lock_init(&vnode->lock);
0667     INIT_LIST_HEAD(&vnode->wb_keys);
0668     INIT_LIST_HEAD(&vnode->pending_locks);
0669     INIT_LIST_HEAD(&vnode->granted_locks);
0670     INIT_DELAYED_WORK(&vnode->lock_work, afs_lock_work);
0671     INIT_LIST_HEAD(&vnode->cb_mmap_link);
0672     seqlock_init(&vnode->cb_lock);
0673 }
0674 
0675 /*
0676  * allocate an AFS inode struct from our slab cache
0677  */
0678 static struct inode *afs_alloc_inode(struct super_block *sb)
0679 {
0680     struct afs_vnode *vnode;
0681 
0682     vnode = alloc_inode_sb(sb, afs_inode_cachep, GFP_KERNEL);
0683     if (!vnode)
0684         return NULL;
0685 
0686     atomic_inc(&afs_count_active_inodes);
0687 
0688     /* Reset anything that shouldn't leak from one inode to the next. */
0689     memset(&vnode->fid, 0, sizeof(vnode->fid));
0690     memset(&vnode->status, 0, sizeof(vnode->status));
0691     afs_vnode_set_cache(vnode, NULL);
0692 
0693     vnode->volume       = NULL;
0694     vnode->lock_key     = NULL;
0695     vnode->permit_cache = NULL;
0696 
0697     vnode->flags        = 1 << AFS_VNODE_UNSET;
0698     vnode->lock_state   = AFS_VNODE_LOCK_NONE;
0699 
0700     init_rwsem(&vnode->rmdir_lock);
0701     INIT_WORK(&vnode->cb_work, afs_invalidate_mmap_work);
0702 
0703     _leave(" = %p", &vnode->netfs.inode);
0704     return &vnode->netfs.inode;
0705 }
0706 
0707 static void afs_free_inode(struct inode *inode)
0708 {
0709     kmem_cache_free(afs_inode_cachep, AFS_FS_I(inode));
0710 }
0711 
0712 /*
0713  * destroy an AFS inode struct
0714  */
0715 static void afs_destroy_inode(struct inode *inode)
0716 {
0717     struct afs_vnode *vnode = AFS_FS_I(inode);
0718 
0719     _enter("%p{%llx:%llu}", inode, vnode->fid.vid, vnode->fid.vnode);
0720 
0721     _debug("DESTROY INODE %p", inode);
0722 
0723     atomic_dec(&afs_count_active_inodes);
0724 }
0725 
0726 static void afs_get_volume_status_success(struct afs_operation *op)
0727 {
0728     struct afs_volume_status *vs = &op->volstatus.vs;
0729     struct kstatfs *buf = op->volstatus.buf;
0730 
0731     if (vs->max_quota == 0)
0732         buf->f_blocks = vs->part_max_blocks;
0733     else
0734         buf->f_blocks = vs->max_quota;
0735 
0736     if (buf->f_blocks > vs->blocks_in_use)
0737         buf->f_bavail = buf->f_bfree =
0738             buf->f_blocks - vs->blocks_in_use;
0739 }
0740 
0741 static const struct afs_operation_ops afs_get_volume_status_operation = {
0742     .issue_afs_rpc  = afs_fs_get_volume_status,
0743     .issue_yfs_rpc  = yfs_fs_get_volume_status,
0744     .success    = afs_get_volume_status_success,
0745 };
0746 
0747 /*
0748  * return information about an AFS volume
0749  */
0750 static int afs_statfs(struct dentry *dentry, struct kstatfs *buf)
0751 {
0752     struct afs_super_info *as = AFS_FS_S(dentry->d_sb);
0753     struct afs_operation *op;
0754     struct afs_vnode *vnode = AFS_FS_I(d_inode(dentry));
0755 
0756     buf->f_type = dentry->d_sb->s_magic;
0757     buf->f_bsize    = AFS_BLOCK_SIZE;
0758     buf->f_namelen  = AFSNAMEMAX - 1;
0759 
0760     if (as->dyn_root) {
0761         buf->f_blocks   = 1;
0762         buf->f_bavail   = 0;
0763         buf->f_bfree    = 0;
0764         return 0;
0765     }
0766 
0767     op = afs_alloc_operation(NULL, as->volume);
0768     if (IS_ERR(op))
0769         return PTR_ERR(op);
0770 
0771     afs_op_set_vnode(op, 0, vnode);
0772     op->nr_files        = 1;
0773     op->volstatus.buf   = buf;
0774     op->ops         = &afs_get_volume_status_operation;
0775     return afs_do_sync_operation(op);
0776 }