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

TOMOYO Linux Cross Reference
Linux/fs/nfsd/flexfilelayout.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Copyright (c) 2016 Tom Haynes <loghyr@primarydata.com>
  4  *
  5  * The following implements a super-simple flex-file server
  6  * where the NFSv4.1 mds is also the ds. And the storage is
  7  * the same. I.e., writing to the mds via a NFSv4.1 WRITE
  8  * goes to the same location as the NFSv3 WRITE.
  9  */
 10 #include <linux/slab.h>
 11 
 12 #include <linux/nfsd/debug.h>
 13 
 14 #include <linux/sunrpc/addr.h>
 15 
 16 #include "flexfilelayoutxdr.h"
 17 #include "pnfs.h"
 18 #include "vfs.h"
 19 
 20 #define NFSDDBG_FACILITY        NFSDDBG_PNFS
 21 
 22 static __be32
 23 nfsd4_ff_proc_layoutget(struct inode *inode, const struct svc_fh *fhp,
 24                 struct nfsd4_layoutget *args)
 25 {
 26         struct nfsd4_layout_seg *seg = &args->lg_seg;
 27         u32 device_generation = 0;
 28         int error;
 29         uid_t u;
 30 
 31         struct pnfs_ff_layout *fl;
 32 
 33         /*
 34          * The super simple flex file server has 1 mirror, 1 data server,
 35          * and 1 file handle. So instead of 4 allocs, do 1 for now.
 36          * Zero it out for the stateid - don't want junk in there!
 37          */
 38         error = -ENOMEM;
 39         fl = kzalloc(sizeof(*fl), GFP_KERNEL);
 40         if (!fl)
 41                 goto out_error;
 42         args->lg_content = fl;
 43 
 44         /*
 45          * Avoid layout commit, try to force the I/O to the DS,
 46          * and for fun, cause all IOMODE_RW layout segments to
 47          * effectively be WRITE only.
 48          */
 49         fl->flags = FF_FLAGS_NO_LAYOUTCOMMIT | FF_FLAGS_NO_IO_THRU_MDS |
 50                     FF_FLAGS_NO_READ_IO;
 51 
 52         /* Do not allow a IOMODE_READ segment to have write pemissions */
 53         if (seg->iomode == IOMODE_READ) {
 54                 u = from_kuid(&init_user_ns, inode->i_uid) + 1;
 55                 fl->uid = make_kuid(&init_user_ns, u);
 56         } else
 57                 fl->uid = inode->i_uid;
 58         fl->gid = inode->i_gid;
 59 
 60         error = nfsd4_set_deviceid(&fl->deviceid, fhp, device_generation);
 61         if (error)
 62                 goto out_error;
 63 
 64         fl->fh.size = fhp->fh_handle.fh_size;
 65         memcpy(fl->fh.data, &fhp->fh_handle.fh_raw, fl->fh.size);
 66 
 67         /* Give whole file layout segments */
 68         seg->offset = 0;
 69         seg->length = NFS4_MAX_UINT64;
 70 
 71         dprintk("GET: 0x%llx:0x%llx %d\n", seg->offset, seg->length,
 72                 seg->iomode);
 73         return 0;
 74 
 75 out_error:
 76         seg->length = 0;
 77         return nfserrno(error);
 78 }
 79 
 80 static __be32
 81 nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp,
 82                 struct nfs4_client *clp, struct nfsd4_getdeviceinfo *gdp)
 83 {
 84         struct pnfs_ff_device_addr *da;
 85 
 86         u16 port;
 87         char addr[INET6_ADDRSTRLEN];
 88 
 89         da = kzalloc(sizeof(struct pnfs_ff_device_addr), GFP_KERNEL);
 90         if (!da)
 91                 return nfserrno(-ENOMEM);
 92 
 93         gdp->gd_device = da;
 94 
 95         da->version = 3;
 96         da->minor_version = 0;
 97 
 98         da->rsize = svc_max_payload(rqstp);
 99         da->wsize = da->rsize;
100 
101         rpc_ntop((struct sockaddr *)&rqstp->rq_daddr,
102                  addr, INET6_ADDRSTRLEN);
103         if (rqstp->rq_daddr.ss_family == AF_INET) {
104                 struct sockaddr_in *sin;
105 
106                 sin = (struct sockaddr_in *)&rqstp->rq_daddr;
107                 port = ntohs(sin->sin_port);
108                 snprintf(da->netaddr.netid, FF_NETID_LEN + 1, "tcp");
109                 da->netaddr.netid_len = 3;
110         } else {
111                 struct sockaddr_in6 *sin6;
112 
113                 sin6 = (struct sockaddr_in6 *)&rqstp->rq_daddr;
114                 port = ntohs(sin6->sin6_port);
115                 snprintf(da->netaddr.netid, FF_NETID_LEN + 1, "tcp6");
116                 da->netaddr.netid_len = 4;
117         }
118 
119         da->netaddr.addr_len =
120                 snprintf(da->netaddr.addr, FF_ADDR_LEN + 1,
121                          "%s.%d.%d", addr, port >> 8, port & 0xff);
122 
123         da->tightly_coupled = false;
124 
125         return 0;
126 }
127 
128 const struct nfsd4_layout_ops ff_layout_ops = {
129         .notify_types           =
130                         NOTIFY_DEVICEID4_DELETE | NOTIFY_DEVICEID4_CHANGE,
131         .disable_recalls        = true,
132         .proc_getdeviceinfo     = nfsd4_ff_proc_getdeviceinfo,
133         .encode_getdeviceinfo   = nfsd4_ff_encode_getdeviceinfo,
134         .proc_layoutget         = nfsd4_ff_proc_layoutget,
135         .encode_layoutget       = nfsd4_ff_encode_layoutget,
136 };
137 

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

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php