Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  Copyright (c) 2006,2007 The Regents of the University of Michigan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Andy Adamson <andros@citi.umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Fred Isaman <iisaman@umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * permission is granted to use, copy, create derivative works and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * redistribute this software and such derivative works for any purpose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * so long as the name of the university of michigan is not used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * any advertising or publicity pertaining to the use or distribution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * of this software without specific, written prior authorization.  if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * the above copyright notice or any other identification of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * university of michigan is included in any copy of any portion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * this software, then the disclaimer below must also be included.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * this software is provided as is, without representation from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * university of michigan as to its fitness for any purpose, and without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * warranty by the university of michigan of any kind, either express
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * or implied, including without limitation the implied warranties of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * merchantability and fitness for a particular purpose.  the regents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * of the university of michigan shall not be liable for any damages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * including special, indirect, incidental, or consequential damages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * with respect to any claim arising out or in connection with the use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * of the software, even if it has been or is hereafter advised of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * possibility of such damages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include "blocklayout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define NFSDBG_FACILITY         NFSDBG_PNFS_LD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) nfs4_encode_simple(__be32 *p, struct pnfs_block_volume *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	*p++ = cpu_to_be32(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	*p++ = cpu_to_be32(b->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	*p++ = cpu_to_be32(b->simple.nr_sigs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	for (i = 0; i < b->simple.nr_sigs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		p = xdr_encode_hyper(p, b->simple.sigs[i].offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		p = xdr_encode_opaque(p, b->simple.sigs[i].sig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 					 b->simple.sigs[i].sig_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) dev_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct net *net = server->nfs_client->cl_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct bl_dev_msg *reply = &nn->bl_mount_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct bl_pipe_msg bl_pipe_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct rpc_pipe_msg *msg = &bl_pipe_msg.msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct bl_msg_hdr *bl_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	DECLARE_WAITQUEUE(wq, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	dev_t dev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	mutex_lock(&nn->bl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	bl_pipe_msg.bl_wq = &nn->bl_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	b->simple.len += 4;	/* single volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (b->simple.len > PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	memset(msg, 0, sizeof(*msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	msg->len = sizeof(*bl_msg) + b->simple.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	msg->data = kzalloc(msg->len, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (!msg->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		goto out_free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	bl_msg = msg->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	bl_msg->type = BL_DEVICE_MOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	bl_msg->totallen = b->simple.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	nfs4_encode_simple(msg->data + sizeof(*bl_msg), b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	dprintk("%s CALLING USERSPACE DAEMON\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	add_wait_queue(&nn->bl_wq, &wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	rc = rpc_queue_upcall(nn->bl_device_pipe, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		remove_wait_queue(&nn->bl_wq, &wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		goto out_free_data;
^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) 	set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	remove_wait_queue(&nn->bl_wq, &wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (reply->status != BL_DEVICE_REQUEST_PROC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		printk(KERN_WARNING "%s failed to decode device: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			__func__, reply->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		goto out_free_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	dev = MKDEV(reply->major, reply->minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) out_free_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kfree(msg->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	mutex_unlock(&nn->bl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static ssize_t bl_pipe_downcall(struct file *filp, const char __user *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			 size_t mlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct nfs_net *nn = net_generic(file_inode(filp)->i_sb->s_fs_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 					 nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (mlen != sizeof (struct bl_dev_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (copy_from_user(&nn->bl_mount_reply, src, mlen) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	wake_up(&nn->bl_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return mlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct bl_pipe_msg *bl_pipe_msg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		container_of(msg, struct bl_pipe_msg, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (msg->errno >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	wake_up(bl_pipe_msg->bl_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static const struct rpc_pipe_ops bl_upcall_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.upcall		= rpc_pipe_generic_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	.downcall	= bl_pipe_downcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.destroy_msg	= bl_pipe_destroy_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 					    struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct dentry *dir, *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (dir == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	dput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void nfs4blocklayout_unregister_sb(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					  struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (pipe->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		rpc_unlink(pipe->dentry);
^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 rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			   void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct super_block *sb = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct net *net = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (nn->bl_device_pipe == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	case RPC_PIPEFS_MOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			ret = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		nn->bl_device_pipe->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	case RPC_PIPEFS_UMOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (nn->bl_device_pipe->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		ret = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static struct notifier_block nfs4blocklayout_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	.notifier_call = rpc_pipefs_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static struct dentry *nfs4blocklayout_register_net(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 						   struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct super_block *pipefs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	pipefs_sb = rpc_get_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (!pipefs_sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	rpc_put_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static void nfs4blocklayout_unregister_net(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 					   struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct super_block *pipefs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	pipefs_sb = rpc_get_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (pipefs_sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		nfs4blocklayout_unregister_sb(pipefs_sb, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		rpc_put_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int nfs4blocklayout_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	mutex_init(&nn->bl_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	init_waitqueue_head(&nn->bl_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (IS_ERR(nn->bl_device_pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return PTR_ERR(nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		rpc_destroy_pipe_data(nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	nn->bl_device_pipe->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static void nfs4blocklayout_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct nfs_net *nn = net_generic(net, nfs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	nfs4blocklayout_unregister_net(net, nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	rpc_destroy_pipe_data(nn->bl_device_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	nn->bl_device_pipe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static struct pernet_operations nfs4blocklayout_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.init = nfs4blocklayout_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.exit = nfs4blocklayout_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int __init bl_init_pipefs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	ret = rpc_pipefs_notifier_register(&nfs4blocklayout_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	ret = register_pernet_subsys(&nfs4blocklayout_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		goto out_unregister_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) out_unregister_notifier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void bl_cleanup_pipefs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	unregister_pernet_subsys(&nfs4blocklayout_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }