Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  linux/fs/nfs/blocklayout/blocklayout.h
0003  *
0004  *  Module for the NFSv4.1 pNFS block layout driver.
0005  *
0006  *  Copyright (c) 2006 The Regents of the University of Michigan.
0007  *  All rights reserved.
0008  *
0009  *  Andy Adamson <andros@citi.umich.edu>
0010  *  Fred Isaman <iisaman@umich.edu>
0011  *
0012  * permission is granted to use, copy, create derivative works and
0013  * redistribute this software and such derivative works for any purpose,
0014  * so long as the name of the university of michigan is not used in
0015  * any advertising or publicity pertaining to the use or distribution
0016  * of this software without specific, written prior authorization.  if
0017  * the above copyright notice or any other identification of the
0018  * university of michigan is included in any copy of any portion of
0019  * this software, then the disclaimer below must also be included.
0020  *
0021  * this software is provided as is, without representation from the
0022  * university of michigan as to its fitness for any purpose, and without
0023  * warranty by the university of michigan of any kind, either express
0024  * or implied, including without limitation the implied warranties of
0025  * merchantability and fitness for a particular purpose.  the regents
0026  * of the university of michigan shall not be liable for any damages,
0027  * including special, indirect, incidental, or consequential damages,
0028  * with respect to any claim arising out or in connection with the use
0029  * of the software, even if it has been or is hereafter advised of the
0030  * possibility of such damages.
0031  */
0032 #ifndef FS_NFS_NFS4BLOCKLAYOUT_H
0033 #define FS_NFS_NFS4BLOCKLAYOUT_H
0034 
0035 #include <linux/device-mapper.h>
0036 #include <linux/nfs_fs.h>
0037 #include <linux/sunrpc/rpc_pipe_fs.h>
0038 
0039 #include "../nfs4_fs.h"
0040 #include "../pnfs.h"
0041 #include "../netns.h"
0042 
0043 #define PAGE_CACHE_SECTORS (PAGE_SIZE >> SECTOR_SHIFT)
0044 #define PAGE_CACHE_SECTOR_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
0045 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
0046 
0047 struct pnfs_block_dev;
0048 
0049 #define PNFS_BLOCK_MAX_UUIDS    4
0050 #define PNFS_BLOCK_MAX_DEVICES  64
0051 
0052 /*
0053  * Random upper cap for the uuid length to avoid unbounded allocation.
0054  * Not actually limited by the protocol.
0055  */
0056 #define PNFS_BLOCK_UUID_LEN 128
0057 
0058 struct pnfs_block_volume {
0059     enum pnfs_block_volume_type type;
0060     union {
0061         struct {
0062             int     len;
0063             int     nr_sigs;
0064             struct {
0065                 u64     offset;
0066                 u32     sig_len;
0067                 u8      sig[PNFS_BLOCK_UUID_LEN];
0068             } sigs[PNFS_BLOCK_MAX_UUIDS];
0069         } simple;
0070         struct {
0071             u64     start;
0072             u64     len;
0073             u32     volume;
0074         } slice;
0075         struct {
0076             u32     volumes_count;
0077             u32     volumes[PNFS_BLOCK_MAX_DEVICES];
0078         } concat;
0079         struct {
0080             u64     chunk_size;
0081             u32     volumes_count;
0082             u32     volumes[PNFS_BLOCK_MAX_DEVICES];
0083         } stripe;
0084         struct {
0085             enum scsi_code_set      code_set;
0086             enum scsi_designator_type   designator_type;
0087             int             designator_len;
0088             u8              designator[256];
0089             u64             pr_key;
0090         } scsi;
0091     };
0092 };
0093 
0094 struct pnfs_block_dev_map {
0095     u64         start;
0096     u64         len;
0097     u64         disk_offset;
0098     struct block_device     *bdev;
0099 };
0100 
0101 struct pnfs_block_dev {
0102     struct nfs4_deviceid_node   node;
0103 
0104     u64             start;
0105     u64             len;
0106 
0107     u32             nr_children;
0108     struct pnfs_block_dev       *children;
0109     u64             chunk_size;
0110 
0111     struct block_device     *bdev;
0112     u64             disk_offset;
0113 
0114     u64             pr_key;
0115     bool                pr_registered;
0116 
0117     bool (*map)(struct pnfs_block_dev *dev, u64 offset,
0118             struct pnfs_block_dev_map *map);
0119 };
0120 
0121 /* sector_t fields are all in 512-byte sectors */
0122 struct pnfs_block_extent {
0123     union {
0124         struct rb_node  be_node;
0125         struct list_head be_list;
0126     };
0127     struct nfs4_deviceid_node *be_device;
0128     sector_t    be_f_offset;    /* the starting offset in the file */
0129     sector_t    be_length;  /* the size of the extent */
0130     sector_t    be_v_offset;    /* the starting offset in the volume */
0131     enum pnfs_block_extent_state be_state;  /* the state of this extent */
0132 #define EXTENT_WRITTEN      1
0133 #define EXTENT_COMMITTING   2
0134     unsigned int    be_tag;
0135 };
0136 
0137 struct pnfs_block_layout {
0138     struct pnfs_layout_hdr  bl_layout;
0139     struct rb_root      bl_ext_rw;
0140     struct rb_root      bl_ext_ro;
0141     spinlock_t      bl_ext_lock;   /* Protects list manipulation */
0142     bool            bl_scsi_layout;
0143     u64         bl_lwb;
0144 };
0145 
0146 static inline struct pnfs_block_layout *
0147 BLK_LO2EXT(struct pnfs_layout_hdr *lo)
0148 {
0149     return container_of(lo, struct pnfs_block_layout, bl_layout);
0150 }
0151 
0152 static inline struct pnfs_block_layout *
0153 BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
0154 {
0155     return BLK_LO2EXT(lseg->pls_layout);
0156 }
0157 
0158 struct bl_pipe_msg {
0159     struct rpc_pipe_msg msg;
0160     wait_queue_head_t *bl_wq;
0161 };
0162 
0163 struct bl_msg_hdr {
0164     u8  type;
0165     u16 totallen; /* length of entire message, including hdr itself */
0166 };
0167 
0168 #define BL_DEVICE_UMOUNT               0x0 /* Umount--delete devices */
0169 #define BL_DEVICE_MOUNT                0x1 /* Mount--create devices*/
0170 #define BL_DEVICE_REQUEST_INIT         0x0 /* Start request */
0171 #define BL_DEVICE_REQUEST_PROC         0x1 /* User level process succeeds */
0172 #define BL_DEVICE_REQUEST_ERR          0x2 /* User level process fails */
0173 
0174 /* dev.c */
0175 struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
0176         struct pnfs_device *pdev, gfp_t gfp_mask);
0177 void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
0178 
0179 /* extent_tree.c */
0180 int ext_tree_insert(struct pnfs_block_layout *bl,
0181         struct pnfs_block_extent *new);
0182 int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
0183         sector_t end);
0184 int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
0185         sector_t len, u64 lwb);
0186 bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
0187         struct pnfs_block_extent *ret, bool rw);
0188 int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
0189 void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
0190 
0191 /* rpc_pipefs.c */
0192 dev_t bl_resolve_deviceid(struct nfs_server *server,
0193         struct pnfs_block_volume *b, gfp_t gfp_mask);
0194 int __init bl_init_pipefs(void);
0195 void bl_cleanup_pipefs(void);
0196 
0197 #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */