xref: /openbmc/linux/fs/nfs/blocklayout/blocklayout.h (revision b3960475)
1155e7524SFred Isaman /*
2155e7524SFred Isaman  *  linux/fs/nfs/blocklayout/blocklayout.h
3155e7524SFred Isaman  *
4155e7524SFred Isaman  *  Module for the NFSv4.1 pNFS block layout driver.
5155e7524SFred Isaman  *
6155e7524SFred Isaman  *  Copyright (c) 2006 The Regents of the University of Michigan.
7155e7524SFred Isaman  *  All rights reserved.
8155e7524SFred Isaman  *
9155e7524SFred Isaman  *  Andy Adamson <andros@citi.umich.edu>
10155e7524SFred Isaman  *  Fred Isaman <iisaman@umich.edu>
11155e7524SFred Isaman  *
12155e7524SFred Isaman  * permission is granted to use, copy, create derivative works and
13155e7524SFred Isaman  * redistribute this software and such derivative works for any purpose,
14155e7524SFred Isaman  * so long as the name of the university of michigan is not used in
15155e7524SFred Isaman  * any advertising or publicity pertaining to the use or distribution
16155e7524SFred Isaman  * of this software without specific, written prior authorization.  if
17155e7524SFred Isaman  * the above copyright notice or any other identification of the
18155e7524SFred Isaman  * university of michigan is included in any copy of any portion of
19155e7524SFred Isaman  * this software, then the disclaimer below must also be included.
20155e7524SFred Isaman  *
21155e7524SFred Isaman  * this software is provided as is, without representation from the
22155e7524SFred Isaman  * university of michigan as to its fitness for any purpose, and without
23155e7524SFred Isaman  * warranty by the university of michigan of any kind, either express
24155e7524SFred Isaman  * or implied, including without limitation the implied warranties of
25155e7524SFred Isaman  * merchantability and fitness for a particular purpose.  the regents
26155e7524SFred Isaman  * of the university of michigan shall not be liable for any damages,
27155e7524SFred Isaman  * including special, indirect, incidental, or consequential damages,
28155e7524SFred Isaman  * with respect to any claim arising out or in connection with the use
29155e7524SFred Isaman  * of the software, even if it has been or is hereafter advised of the
30155e7524SFred Isaman  * possibility of such damages.
31155e7524SFred Isaman  */
32155e7524SFred Isaman #ifndef FS_NFS_NFS4BLOCKLAYOUT_H
33155e7524SFred Isaman #define FS_NFS_NFS4BLOCKLAYOUT_H
34155e7524SFred Isaman 
35155e7524SFred Isaman #include <linux/device-mapper.h>
36155e7524SFred Isaman #include <linux/nfs_fs.h>
37fe0a9b74SJim Rees #include <linux/sunrpc/rpc_pipe_fs.h>
38fe0a9b74SJim Rees 
39694e096fSAnna Schumaker #include "../nfs4_fs.h"
40155e7524SFred Isaman #include "../pnfs.h"
419e2e74dbSStanislav Kinsbursky #include "../netns.h"
42155e7524SFred Isaman 
4309cbfeafSKirill A. Shutemov #define PAGE_CACHE_SECTORS (PAGE_SIZE >> SECTOR_SHIFT)
4409cbfeafSKirill A. Shutemov #define PAGE_CACHE_SECTOR_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
45fe6e1e8dSPeng Tao #define SECTOR_SIZE (1 << SECTOR_SHIFT)
46c1c2a4cdSFred Isaman 
475c83746aSChristoph Hellwig struct pnfs_block_dev;
485c83746aSChristoph Hellwig 
495c83746aSChristoph Hellwig #define PNFS_BLOCK_MAX_UUIDS	4
505c83746aSChristoph Hellwig #define PNFS_BLOCK_MAX_DEVICES	64
515c83746aSChristoph Hellwig 
525c83746aSChristoph Hellwig /*
535c83746aSChristoph Hellwig  * Random upper cap for the uuid length to avoid unbounded allocation.
545c83746aSChristoph Hellwig  * Not actually limited by the protocol.
555c83746aSChristoph Hellwig  */
565c83746aSChristoph Hellwig #define PNFS_BLOCK_UUID_LEN	128
575c83746aSChristoph Hellwig 
585c83746aSChristoph Hellwig struct pnfs_block_volume {
595c83746aSChristoph Hellwig 	enum pnfs_block_volume_type	type;
605c83746aSChristoph Hellwig 	union {
615c83746aSChristoph Hellwig 		struct {
625c83746aSChristoph Hellwig 			int		len;
635c83746aSChristoph Hellwig 			int		nr_sigs;
645c83746aSChristoph Hellwig 			struct {
655c83746aSChristoph Hellwig 				u64		offset;
665c83746aSChristoph Hellwig 				u32		sig_len;
675c83746aSChristoph Hellwig 				u8		sig[PNFS_BLOCK_UUID_LEN];
685c83746aSChristoph Hellwig 			} sigs[PNFS_BLOCK_MAX_UUIDS];
695c83746aSChristoph Hellwig 		} simple;
705c83746aSChristoph Hellwig 		struct {
715c83746aSChristoph Hellwig 			u64		start;
725c83746aSChristoph Hellwig 			u64		len;
735c83746aSChristoph Hellwig 			u32		volume;
745c83746aSChristoph Hellwig 		} slice;
755c83746aSChristoph Hellwig 		struct {
765c83746aSChristoph Hellwig 			u32		volumes_count;
775c83746aSChristoph Hellwig 			u32		volumes[PNFS_BLOCK_MAX_DEVICES];
785c83746aSChristoph Hellwig 		} concat;
795c83746aSChristoph Hellwig 		struct {
805c83746aSChristoph Hellwig 			u64		chunk_size;
815c83746aSChristoph Hellwig 			u32		volumes_count;
825c83746aSChristoph Hellwig 			u32		volumes[PNFS_BLOCK_MAX_DEVICES];
835c83746aSChristoph Hellwig 		} stripe;
84d9186c03SChristoph Hellwig 		struct {
85d9186c03SChristoph Hellwig 			enum scsi_code_set		code_set;
86d9186c03SChristoph Hellwig 			enum scsi_designator_type	designator_type;
87d9186c03SChristoph Hellwig 			int				designator_len;
88d9186c03SChristoph Hellwig 			u8				designator[256];
89d9186c03SChristoph Hellwig 			u64				pr_key;
90d9186c03SChristoph Hellwig 		} scsi;
915c83746aSChristoph Hellwig 	};
925c83746aSChristoph Hellwig };
935c83746aSChristoph Hellwig 
945c83746aSChristoph Hellwig struct pnfs_block_dev_map {
95b3960475SBenjamin Coddington 	u64			start;
96b3960475SBenjamin Coddington 	u64			len;
97b3960475SBenjamin Coddington 	u64			disk_offset;
985c83746aSChristoph Hellwig 	struct block_device		*bdev;
995c83746aSChristoph Hellwig };
1005c83746aSChristoph Hellwig 
101fe0a9b74SJim Rees struct pnfs_block_dev {
1025c83746aSChristoph Hellwig 	struct nfs4_deviceid_node	node;
1035c83746aSChristoph Hellwig 
1045c83746aSChristoph Hellwig 	u64				start;
1055c83746aSChristoph Hellwig 	u64				len;
1065c83746aSChristoph Hellwig 
1075c83746aSChristoph Hellwig 	u32				nr_children;
1085c83746aSChristoph Hellwig 	struct pnfs_block_dev		*children;
1095c83746aSChristoph Hellwig 	u64				chunk_size;
1105c83746aSChristoph Hellwig 
1115c83746aSChristoph Hellwig 	struct block_device		*bdev;
1125c83746aSChristoph Hellwig 	u64				disk_offset;
1135c83746aSChristoph Hellwig 
114d9186c03SChristoph Hellwig 	u64				pr_key;
115d9186c03SChristoph Hellwig 	bool				pr_registered;
116d9186c03SChristoph Hellwig 
1175c83746aSChristoph Hellwig 	bool (*map)(struct pnfs_block_dev *dev, u64 offset,
1185c83746aSChristoph Hellwig 			struct pnfs_block_dev_map *map);
119fe0a9b74SJim Rees };
120fe0a9b74SJim Rees 
121155e7524SFred Isaman /* sector_t fields are all in 512-byte sectors */
122155e7524SFred Isaman struct pnfs_block_extent {
1238067253cSChristoph Hellwig 	union {
1248067253cSChristoph Hellwig 		struct rb_node	be_node;
1258067253cSChristoph Hellwig 		struct list_head be_list;
1268067253cSChristoph Hellwig 	};
12720d655d6SChristoph Hellwig 	struct nfs4_deviceid_node *be_device;
128155e7524SFred Isaman 	sector_t	be_f_offset;	/* the starting offset in the file */
129155e7524SFred Isaman 	sector_t	be_length;	/* the size of the extent */
130155e7524SFred Isaman 	sector_t	be_v_offset;	/* the starting offset in the volume */
1318bb28975SChristoph Hellwig 	enum pnfs_block_extent_state be_state;	/* the state of this extent */
1328067253cSChristoph Hellwig #define EXTENT_WRITTEN		1
1338067253cSChristoph Hellwig #define EXTENT_COMMITTING	2
1348067253cSChristoph Hellwig 	unsigned int	be_tag;
135155e7524SFred Isaman };
136155e7524SFred Isaman 
137155e7524SFred Isaman struct pnfs_block_layout {
138155e7524SFred Isaman 	struct pnfs_layout_hdr	bl_layout;
1398067253cSChristoph Hellwig 	struct rb_root		bl_ext_rw;
1408067253cSChristoph Hellwig 	struct rb_root		bl_ext_ro;
141155e7524SFred Isaman 	spinlock_t		bl_ext_lock;   /* Protects list manipulation */
142d9186c03SChristoph Hellwig 	bool			bl_scsi_layout;
14341963c10SBenjamin Coddington 	u64			bl_lwb;
144155e7524SFred Isaman };
145155e7524SFred Isaman 
1462f9fd182SFred Isaman static inline struct pnfs_block_layout *
BLK_LO2EXT(struct pnfs_layout_hdr * lo)1472f9fd182SFred Isaman BLK_LO2EXT(struct pnfs_layout_hdr *lo)
148155e7524SFred Isaman {
149155e7524SFred Isaman 	return container_of(lo, struct pnfs_block_layout, bl_layout);
150155e7524SFred Isaman }
151155e7524SFred Isaman 
152a60d2ebdSFred Isaman static inline struct pnfs_block_layout *
BLK_LSEG2EXT(struct pnfs_layout_segment * lseg)153a60d2ebdSFred Isaman BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
154a60d2ebdSFred Isaman {
155a60d2ebdSFred Isaman 	return BLK_LO2EXT(lseg->pls_layout);
156a60d2ebdSFred Isaman }
157a60d2ebdSFred Isaman 
1585ffaf855SStanislav Kinsbursky struct bl_pipe_msg {
1595ffaf855SStanislav Kinsbursky 	struct rpc_pipe_msg msg;
1605ffaf855SStanislav Kinsbursky 	wait_queue_head_t *bl_wq;
1615ffaf855SStanislav Kinsbursky };
1625ffaf855SStanislav Kinsbursky 
163fe0a9b74SJim Rees struct bl_msg_hdr {
164fe0a9b74SJim Rees 	u8  type;
165fe0a9b74SJim Rees 	u16 totallen; /* length of entire message, including hdr itself */
166fe0a9b74SJim Rees };
167fe0a9b74SJim Rees 
168fe0a9b74SJim Rees #define BL_DEVICE_UMOUNT               0x0 /* Umount--delete devices */
169fe0a9b74SJim Rees #define BL_DEVICE_MOUNT                0x1 /* Mount--create devices*/
170fe0a9b74SJim Rees #define BL_DEVICE_REQUEST_INIT         0x0 /* Start request */
171fe0a9b74SJim Rees #define BL_DEVICE_REQUEST_PROC         0x1 /* User level process succeeds */
172fe0a9b74SJim Rees #define BL_DEVICE_REQUEST_ERR          0x2 /* User level process fails */
173fe0a9b74SJim Rees 
1745c83746aSChristoph Hellwig /* dev.c */
1755c83746aSChristoph Hellwig struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
1765c83746aSChristoph Hellwig 		struct pnfs_device *pdev, gfp_t gfp_mask);
1775c83746aSChristoph Hellwig void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
1785c83746aSChristoph Hellwig 
1798067253cSChristoph Hellwig /* extent_tree.c */
1808067253cSChristoph Hellwig int ext_tree_insert(struct pnfs_block_layout *bl,
18103341d2cSFred Isaman 		struct pnfs_block_extent *new);
1828067253cSChristoph Hellwig int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
1838067253cSChristoph Hellwig 		sector_t end);
1848067253cSChristoph Hellwig int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
18541963c10SBenjamin Coddington 		sector_t len, u64 lwb);
1868067253cSChristoph Hellwig bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
1878067253cSChristoph Hellwig 		struct pnfs_block_extent *ret, bool rw);
18834dc93c2SChristoph Hellwig int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
18934dc93c2SChristoph Hellwig void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
19003341d2cSFred Isaman 
191871760ceSChristoph Hellwig /* rpc_pipefs.c */
1925c83746aSChristoph Hellwig dev_t bl_resolve_deviceid(struct nfs_server *server,
1935c83746aSChristoph Hellwig 		struct pnfs_block_volume *b, gfp_t gfp_mask);
194871760ceSChristoph Hellwig int __init bl_init_pipefs(void);
195d9186c03SChristoph Hellwig void bl_cleanup_pipefs(void);
196871760ceSChristoph Hellwig 
197155e7524SFred Isaman #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */
198