^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * dlmfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Code which implements the kernel side of a minimal userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * interface to our DLM. This file handles the virtual file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * used for communication with userspace. Credit should go to ramfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * which was a template for the fs side of this module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 2003, 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* Simple VFS hooks based on: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Resizable simple ram filesystem for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Copyright (C) 2000 Linus Torvalds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * 2000 Transmeta Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "../stackglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "userdlm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define MLOG_MASK_PREFIX ML_DLMFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "../cluster/masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const struct super_operations dlmfs_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct file_operations dlmfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct inode_operations dlmfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static const struct inode_operations dlmfs_root_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const struct inode_operations dlmfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct kmem_cache *dlmfs_inode_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct workqueue_struct *user_dlm_worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * These are the ABI capabilities of dlmfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Over time, dlmfs has added some features that were not part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * initial ABI. Unfortunately, some of these features are not detectable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * via standard usage. For example, Linux's default poll always returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * EPOLLIN, so there is no way for a caller of poll(2) to know when dlmfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * added poll support. Instead, we provide this list of new capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Capabilities is a read-only attribute. We do it as a module parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * so we can discover it whether dlmfs is built in, loaded, or even not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * loaded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * The ABI features are local to this machine's dlmfs mount. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * distinct from the locking protocol, which is concerned with inter-node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * interaction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * Capabilities:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * - bast : EPOLLIN against the file descriptor of a held lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * signifies a bast fired on the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define DLMFS_CAPABILITIES "bast stackglue"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int param_set_dlmfs_capabilities(const char *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printk(KERN_ERR "%s: readonly parameter\n", kp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int param_get_dlmfs_capabilities(char *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return strlcpy(buffer, DLMFS_CAPABILITIES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) strlen(DLMFS_CAPABILITIES) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) module_param_call(capabilities, param_set_dlmfs_capabilities,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) param_get_dlmfs_capabilities, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_PARM_DESC(capabilities, DLMFS_CAPABILITIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * decodes a set of open flags into a valid lock level and a set of flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * returns < 0 if we have invalid flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * flags which mean something to us:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * O_RDONLY -> PRMODE level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * O_WRONLY -> EXMODE level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * O_NONBLOCK -> NOQUEUE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int dlmfs_decode_open_flags(int open_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int *level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (open_flags & (O_WRONLY|O_RDWR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *level = DLM_LOCK_EX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *level = DLM_LOCK_PR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) *flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (open_flags & O_NONBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *flags |= DLM_LKF_NOQUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int dlmfs_file_open(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int status, level, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct dlmfs_filp_private *fp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct dlmfs_inode_private *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) mlog(0, "open called on inode %lu, flags 0x%x\n", inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) file->f_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) status = dlmfs_decode_open_flags(file->f_flags, &level, &flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* We don't want to honor O_APPEND at read/write time as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * doesn't make sense for LVB writes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) file->f_flags &= ~O_APPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) fp = kmalloc(sizeof(*fp), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (!fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) fp->fp_lock_level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) status = user_dlm_cluster_lock(&ip->ip_lockres, level, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* this is a strange error to return here but I want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * to be able userspace to be able to distinguish a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * valid lock request from one that simply couldn't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * granted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (flags & DLM_LKF_NOQUEUE && status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) status = -ETXTBSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) kfree(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) file->private_data = fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int dlmfs_file_release(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct dlmfs_inode_private *ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct dlmfs_filp_private *fp = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) mlog(0, "close called on inode %lu\n", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) level = fp->fp_lock_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (level != DLM_LOCK_IV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) user_dlm_cluster_unlock(&ip->ip_lockres, level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) kfree(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * We do ->setattr() just to override size changes. Our size is the size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * of the LVB and nothing else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) attr->ia_valid &= ~ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) error = setattr_prepare(dentry, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) setattr_copy(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static __poll_t dlmfs_file_poll(struct file *file, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) __poll_t event = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct dlmfs_inode_private *ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) poll_wait(file, &ip->ip_lockres.l_event, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) spin_lock(&ip->ip_lockres.l_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (ip->ip_lockres.l_flags & USER_LOCK_BLOCKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) event = EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) spin_unlock(&ip->ip_lockres.l_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static ssize_t dlmfs_file_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) char lvb[DLM_LVB_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (!user_dlm_read_lvb(file_inode(file), lvb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return simple_read_from_buffer(buf, count, ppos, lvb, sizeof(lvb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static ssize_t dlmfs_file_write(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) char lvb_buf[DLM_LVB_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int bytes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) inode->i_ino, count, *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (*ppos >= DLM_LVB_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* don't write past the lvb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (count > DLM_LVB_LEN - *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) count = DLM_LVB_LEN - *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) bytes_left = copy_from_user(lvb_buf, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) count -= bytes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) user_dlm_write_lvb(inode, lvb_buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) *ppos = *ppos + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) mlog(0, "wrote %zu bytes\n", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static void dlmfs_init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct dlmfs_inode_private *ip =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) (struct dlmfs_inode_private *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ip->ip_conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ip->ip_parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) inode_init_once(&ip->ip_vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static struct inode *dlmfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct dlmfs_inode_private *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ip = kmem_cache_alloc(dlmfs_inode_cache, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return &ip->ip_vfs_inode;
^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 void dlmfs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) kmem_cache_free(dlmfs_inode_cache, DLMFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void dlmfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct dlmfs_inode_private *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mlog(0, "inode %lu\n", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) status = user_dlm_destroy_lock(&ip->ip_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) iput(ip->ip_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) goto clear_fields;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) mlog(0, "we're a directory, ip->ip_conn = 0x%p\n", ip->ip_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* we must be a directory. If required, lets unregister the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * dlm context now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (ip->ip_conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) user_dlm_unregister(ip->ip_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) clear_fields:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ip->ip_parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ip->ip_conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct inode *dlmfs_get_root_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct inode *inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) umode_t mode = S_IFDIR | 0755;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) inode->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) inode_init_owner(inode, NULL, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) inode->i_op = &dlmfs_root_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static struct inode *dlmfs_get_inode(struct inode *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct super_block *sb = parent->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct inode * inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct dlmfs_inode_private *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) inode->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) inode_init_owner(inode, parent, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ip->ip_conn = DLMFS_I(parent)->ip_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) switch (mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* for now we don't support anything other than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * directories and regular files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) inode->i_op = &dlmfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) inode->i_fop = &dlmfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) i_size_write(inode, DLM_LVB_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) user_dlm_lock_res_init(&ip->ip_lockres, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* released at clear_inode time, this insures that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * get to drop the dlm reference on each lock *before*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * we call the unregister code for releasing parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * directories. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ip->ip_parent = igrab(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) BUG_ON(!ip->ip_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) inode->i_op = &dlmfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* directory inodes start off with i_nlink ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * 2 (for "." entry) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * File creation. Allocate an inode, and we're done..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* SMP-safe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int dlmfs_mkdir(struct inode * dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct dentry * dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) const struct qstr *domain = &dentry->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct dlmfs_inode_private *ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct ocfs2_cluster_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) mlog(0, "mkdir %.*s\n", domain->len, domain->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* verify that we have a proper domain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (domain->len >= GROUP_NAME_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) mlog(ML_ERROR, "invalid domain name for directory.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) inode = dlmfs_get_inode(dir, dentry, mode | S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ip = DLMFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) conn = user_dlm_register(domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (IS_ERR(conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) status = PTR_ERR(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mlog(ML_ERROR, "Error %d could not register domain \"%.*s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) status, domain->len, domain->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ip->ip_conn = conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) dget(dentry); /* Extra count - pin the dentry in core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static int dlmfs_create(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) bool excl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) const struct qstr *name = &dentry->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) mlog(0, "create %.*s\n", name->len, name->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* verify name is valid and doesn't contain any dlm reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * characters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (name->len >= USER_DLM_LOCK_ID_MAX_LEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) name->name[0] == '$') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) mlog(ML_ERROR, "invalid lock name, %.*s\n", name->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) name->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) inode = dlmfs_get_inode(dir, dentry, mode | S_IFREG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) dget(dentry); /* Extra count - pin the dentry in core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static int dlmfs_unlink(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) mlog(0, "unlink inode %lu\n", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* if there are no current holders, or none that are waiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * to acquire a lock, this basically destroys our lockres. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) status = user_dlm_destroy_lock(&DLMFS_I(inode)->ip_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) mlog(ML_ERROR, "unlink %pd, error %d from destroy\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) dentry, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) status = simple_unlink(dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static int dlmfs_fill_super(struct super_block * sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) void * data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) sb->s_blocksize = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) sb->s_blocksize_bits = PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) sb->s_magic = DLMFS_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) sb->s_op = &dlmfs_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) sb->s_root = d_make_root(dlmfs_get_root_inode(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (!sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static const struct file_operations dlmfs_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) .open = dlmfs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) .release = dlmfs_file_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) .poll = dlmfs_file_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) .read = dlmfs_file_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) .write = dlmfs_file_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) .llseek = default_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static const struct inode_operations dlmfs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) .create = dlmfs_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .lookup = simple_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) .unlink = dlmfs_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* this way we can restrict mkdir to only the toplevel of the fs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static const struct inode_operations dlmfs_root_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) .lookup = simple_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) .mkdir = dlmfs_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) .rmdir = simple_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static const struct super_operations dlmfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .statfs = simple_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .alloc_inode = dlmfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .free_inode = dlmfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .evict_inode = dlmfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .drop_inode = generic_delete_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static const struct inode_operations dlmfs_file_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .getattr = simple_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .setattr = dlmfs_file_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static struct dentry *dlmfs_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return mount_nodev(fs_type, flags, data, dlmfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static struct file_system_type dlmfs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) .name = "ocfs2_dlmfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) .mount = dlmfs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) .kill_sb = kill_litter_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) MODULE_ALIAS_FS("ocfs2_dlmfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static int __init init_dlmfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int cleanup_inode = 0, cleanup_worker = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) dlmfs_inode_cache = kmem_cache_create("dlmfs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) sizeof(struct dlmfs_inode_private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) dlmfs_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) if (!dlmfs_inode_cache) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) cleanup_inode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) user_dlm_worker = alloc_workqueue("user_dlm", WQ_MEM_RECLAIM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!user_dlm_worker) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) cleanup_worker = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) user_dlm_set_locking_protocol();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) status = register_filesystem(&dlmfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (cleanup_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) kmem_cache_destroy(dlmfs_inode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (cleanup_worker)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) destroy_workqueue(user_dlm_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) printk("OCFS2 User DLM kernel interface loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static void __exit exit_dlmfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) unregister_filesystem(&dlmfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) destroy_workqueue(user_dlm_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) kmem_cache_destroy(dlmfs_inode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) MODULE_AUTHOR("Oracle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) MODULE_DESCRIPTION("OCFS2 DLM-Filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) module_init(init_dlmfs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) module_exit(exit_dlmfs_fs)