^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Super block/filesystem wide operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1996 Peter J. Braam <braam@maths.ox.ac.uk> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Michael Callahan <callahan@maths.ox.ac.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Rewritten for Linux 2.1. Peter Braam <braam@cs.cmu.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) Carnegie Mellon University
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/pid_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/coda.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "coda_psdev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "coda_linux.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "coda_cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "coda_int.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* VFS super_block ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static void coda_evict_inode(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void coda_put_super(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int coda_statfs(struct dentry *dentry, struct kstatfs *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static struct kmem_cache * coda_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static struct inode *coda_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct coda_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ei = kmem_cache_alloc(coda_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) memset(&ei->c_fid, 0, sizeof(struct CodaFid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ei->c_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ei->c_uid = GLOBAL_ROOT_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ei->c_cached_perm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) spin_lock_init(&ei->c_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static void coda_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) kmem_cache_free(coda_inode_cachep, ITOC(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct coda_inode_info *ei = (struct coda_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int __init coda_init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) coda_inode_cachep = kmem_cache_create("coda_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) sizeof(struct coda_inode_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) SLAB_ACCOUNT, init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (coda_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void coda_destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) kmem_cache_destroy(coda_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int coda_remount(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *flags |= SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* exported operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static const struct super_operations coda_super_operations =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .alloc_inode = coda_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .free_inode = coda_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .evict_inode = coda_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .put_super = coda_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .statfs = coda_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .remount_fs = coda_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int get_device_index(struct coda_mount_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct fd f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) pr_warn("%s: Bad mount data\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (data->version != CODA_MOUNT_VERSION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) pr_warn("%s: Bad mount version\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) f = fdget(data->fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!f.file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) goto Ebadf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) inode = file_inode(f.file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!S_ISCHR(inode->i_mode) || imajor(inode) != CODA_PSDEV_MAJOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) fdput(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) goto Ebadf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) idx = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) fdput(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (idx < 0 || idx >= MAX_CODADEVS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) pr_warn("%s: Bad minor number\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) Ebadf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) pr_warn("%s: Bad file\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int coda_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct inode *root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct venus_comm *vc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct CodaFid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (task_active_pid_ns(current) != &init_pid_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) idx = get_device_index((struct coda_mount_data *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Ignore errors in data, for backward compatibility */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if(idx == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) pr_info("%s: device index: %i\n", __func__, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) vc = &coda_comms[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mutex_lock(&vc->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (!vc->vc_inuse) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) pr_warn("%s: No pseudo device\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) goto unlock_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (vc->vc_sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) pr_warn("%s: Device already mounted\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) goto unlock_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) vc->vc_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) mutex_unlock(&vc->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) sb->s_fs_info = vc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) sb->s_flags |= SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) sb->s_blocksize = 4096; /* XXXXX what do we put here?? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sb->s_blocksize_bits = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) sb->s_magic = CODA_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) sb->s_op = &coda_super_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) sb->s_d_op = &coda_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sb->s_time_min = S64_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) sb->s_time_max = S64_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) error = super_setup_bdi(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* get root fid from Venus: this needs the root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) error = venus_rootfid(sb, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if ( error ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) pr_warn("%s: coda_get_rootfid failed with %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) __func__, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) pr_info("%s: rootfid is %s\n", __func__, coda_f2s(&fid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* make root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) root = coda_cnode_make(&fid, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (IS_ERR(root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) error = PTR_ERR(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pr_warn("Failure of coda_cnode_make for root: error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) pr_info("%s: rootinode is %ld dev %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) __func__, root->i_ino, root->i_sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sb->s_root = d_make_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) mutex_lock(&vc->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) vc->vc_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unlock_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) mutex_unlock(&vc->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static void coda_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct venus_comm *vcp = coda_vcp(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) mutex_lock(&vcp->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) vcp->vc_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) mutex_unlock(&vcp->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) mutex_destroy(&vcp->vc_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pr_info("Bye bye.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void coda_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) coda_cache_clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int coda_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int err = coda_revalidate_inode(d_inode(path->dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) generic_fillattr(d_inode(path->dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int coda_setattr(struct dentry *de, struct iattr *iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct inode *inode = d_inode(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct coda_vattr vattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) memset(&vattr, 0, sizeof(vattr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) coda_iattr_to_vattr(iattr, &vattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) vattr.va_type = C_VNON; /* cannot set type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* Venus is responsible for truncating the container-file!!! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) error = venus_setattr(inode->i_sb, coda_i2f(inode), &vattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) coda_vattr_to_iattr(inode, &vattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) coda_cache_clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) const struct inode_operations coda_file_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .permission = coda_permission,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .getattr = coda_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .setattr = coda_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int coda_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) error = venus_statfs(dentry, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* fake something like AFS does */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) buf->f_blocks = 9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) buf->f_bfree = 9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) buf->f_bavail = 9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) buf->f_files = 9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) buf->f_ffree = 9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* and fill in the rest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) buf->f_type = CODA_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) buf->f_bsize = 4096;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) buf->f_namelen = CODA_MAXNAMLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /* init_coda: used by filesystems.c to register coda */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static struct dentry *coda_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return mount_nodev(fs_type, flags, data, coda_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct file_system_type coda_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .name = "coda",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .mount = coda_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .kill_sb = kill_anon_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .fs_flags = FS_BINARY_MOUNTDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) MODULE_ALIAS_FS("coda");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)