Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/blocklayout/blocklayout.c |
| 3 | * |
| 4 | * Module for the NFSv4.1 pNFS block layout driver. |
| 5 | * |
| 6 | * Copyright (c) 2006 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Andy Adamson <andros@citi.umich.edu> |
| 10 | * Fred Isaman <iisaman@umich.edu> |
| 11 | * |
| 12 | * permission is granted to use, copy, create derivative works and |
| 13 | * redistribute this software and such derivative works for any purpose, |
| 14 | * so long as the name of the university of michigan is not used in |
| 15 | * any advertising or publicity pertaining to the use or distribution |
| 16 | * of this software without specific, written prior authorization. if |
| 17 | * the above copyright notice or any other identification of the |
| 18 | * university of michigan is included in any copy of any portion of |
| 19 | * this software, then the disclaimer below must also be included. |
| 20 | * |
| 21 | * this software is provided as is, without representation from the |
| 22 | * university of michigan as to its fitness for any purpose, and without |
| 23 | * warranty by the university of michigan of any kind, either express |
| 24 | * or implied, including without limitation the implied warranties of |
| 25 | * merchantability and fitness for a particular purpose. the regents |
| 26 | * of the university of michigan shall not be liable for any damages, |
| 27 | * including special, indirect, incidental, or consequential damages, |
| 28 | * with respect to any claim arising out or in connection with the use |
| 29 | * of the software, even if it has been or is hereafter advised of the |
| 30 | * possibility of such damages. |
| 31 | */ |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 32 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/init.h> |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 35 | #include <linux/mount.h> |
| 36 | #include <linux/namei.h> |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 37 | #include <linux/bio.h> /* struct bio */ |
Heiko Carstens | 88c9e42 | 2011-08-02 09:57:35 +0200 | [diff] [blame] | 38 | #include <linux/prefetch.h> |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 39 | #include <linux/pagevec.h> |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 40 | |
Jim Rees | 10bd295 | 2012-04-09 22:33:39 -0400 | [diff] [blame] | 41 | #include "../pnfs.h" |
Trond Myklebust | 76e697b | 2012-11-26 14:20:49 -0500 | [diff] [blame] | 42 | #include "../nfs4session.h" |
Jim Rees | 10bd295 | 2012-04-09 22:33:39 -0400 | [diff] [blame] | 43 | #include "../internal.h" |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 44 | #include "blocklayout.h" |
| 45 | |
| 46 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 47 | |
| 48 | MODULE_LICENSE("GPL"); |
| 49 | MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>"); |
| 50 | MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver"); |
| 51 | |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 52 | static bool is_hole(struct pnfs_block_extent *be) |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 53 | { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 54 | switch (be->be_state) { |
| 55 | case PNFS_BLOCK_NONE_DATA: |
| 56 | return true; |
| 57 | case PNFS_BLOCK_INVALID_DATA: |
| 58 | return be->be_tag ? false : true; |
| 59 | default: |
| 60 | return false; |
| 61 | } |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 64 | /* The data we are handed might be spread across several bios. We need |
| 65 | * to track when the last one is finished. |
| 66 | */ |
| 67 | struct parallel_io { |
| 68 | struct kref refcnt; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 69 | void (*pnfs_callback) (void *data); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 70 | void *data; |
| 71 | }; |
| 72 | |
| 73 | static inline struct parallel_io *alloc_parallel(void *data) |
| 74 | { |
| 75 | struct parallel_io *rv; |
| 76 | |
| 77 | rv = kmalloc(sizeof(*rv), GFP_NOFS); |
| 78 | if (rv) { |
| 79 | rv->data = data; |
| 80 | kref_init(&rv->refcnt); |
| 81 | } |
| 82 | return rv; |
| 83 | } |
| 84 | |
| 85 | static inline void get_parallel(struct parallel_io *p) |
| 86 | { |
| 87 | kref_get(&p->refcnt); |
| 88 | } |
| 89 | |
| 90 | static void destroy_parallel(struct kref *kref) |
| 91 | { |
| 92 | struct parallel_io *p = container_of(kref, struct parallel_io, refcnt); |
| 93 | |
| 94 | dprintk("%s enter\n", __func__); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 95 | p->pnfs_callback(p->data); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 96 | kfree(p); |
| 97 | } |
| 98 | |
| 99 | static inline void put_parallel(struct parallel_io *p) |
| 100 | { |
| 101 | kref_put(&p->refcnt, destroy_parallel); |
| 102 | } |
| 103 | |
| 104 | static struct bio * |
| 105 | bl_submit_bio(int rw, struct bio *bio) |
| 106 | { |
| 107 | if (bio) { |
| 108 | get_parallel(bio->bi_private); |
| 109 | dprintk("%s submitting %s bio %u@%llu\n", __func__, |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 110 | rw == READ ? "read" : "write", bio->bi_iter.bi_size, |
| 111 | (unsigned long long)bio->bi_iter.bi_sector); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 112 | submit_bio(rw, bio); |
| 113 | } |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | static struct bio *bl_alloc_init_bio(int npg, sector_t isect, |
| 118 | struct pnfs_block_extent *be, |
| 119 | void (*end_io)(struct bio *, int err), |
| 120 | struct parallel_io *par) |
| 121 | { |
| 122 | struct bio *bio; |
| 123 | |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 124 | npg = min(npg, BIO_MAX_PAGES); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 125 | bio = bio_alloc(GFP_NOIO, npg); |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 126 | if (!bio && (current->flags & PF_MEMALLOC)) { |
| 127 | while (!bio && (npg /= 2)) |
| 128 | bio = bio_alloc(GFP_NOIO, npg); |
| 129 | } |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 130 | |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 131 | if (bio) { |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 132 | bio->bi_iter.bi_sector = isect - be->be_f_offset + |
| 133 | be->be_v_offset; |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 134 | bio->bi_bdev = be->be_mdev; |
| 135 | bio->bi_end_io = end_io; |
| 136 | bio->bi_private = par; |
| 137 | } |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 138 | return bio; |
| 139 | } |
| 140 | |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 141 | static struct bio *do_add_page_to_bio(struct bio *bio, int npg, int rw, |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 142 | sector_t isect, struct page *page, |
| 143 | struct pnfs_block_extent *be, |
| 144 | void (*end_io)(struct bio *, int err), |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 145 | struct parallel_io *par, |
| 146 | unsigned int offset, int len) |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 147 | { |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 148 | isect = isect + (offset >> SECTOR_SHIFT); |
| 149 | dprintk("%s: npg %d rw %d isect %llu offset %u len %d\n", __func__, |
| 150 | npg, rw, (unsigned long long)isect, offset, len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 151 | retry: |
| 152 | if (!bio) { |
| 153 | bio = bl_alloc_init_bio(npg, isect, be, end_io, par); |
| 154 | if (!bio) |
| 155 | return ERR_PTR(-ENOMEM); |
| 156 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 157 | if (bio_add_page(bio, page, len, offset) < len) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 158 | bio = bl_submit_bio(rw, bio); |
| 159 | goto retry; |
| 160 | } |
| 161 | return bio; |
| 162 | } |
| 163 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 164 | static void bl_end_io_read(struct bio *bio, int err) |
| 165 | { |
| 166 | struct parallel_io *par = bio->bi_private; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 167 | |
Kent Overstreet | 2c30c71 | 2013-11-07 12:20:26 -0800 | [diff] [blame] | 168 | if (err) { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 169 | struct nfs_pgio_header *header = par->data; |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 170 | |
| 171 | if (!header->pnfs_error) |
| 172 | header->pnfs_error = -EIO; |
| 173 | pnfs_set_lo_fail(header->lseg); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 174 | } |
Christoph Hellwig | 8c792ea | 2014-09-10 08:23:33 -0700 | [diff] [blame] | 175 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 176 | bio_put(bio); |
| 177 | put_parallel(par); |
| 178 | } |
| 179 | |
| 180 | static void bl_read_cleanup(struct work_struct *work) |
| 181 | { |
| 182 | struct rpc_task *task; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 183 | struct nfs_pgio_header *hdr; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 184 | dprintk("%s enter\n", __func__); |
| 185 | task = container_of(work, struct rpc_task, u.tk_work); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 186 | hdr = container_of(task, struct nfs_pgio_header, task); |
| 187 | pnfs_ld_read_done(hdr); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static void |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 191 | bl_end_par_io_read(void *data) |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 192 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 193 | struct nfs_pgio_header *hdr = data; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 194 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 195 | hdr->task.tk_status = hdr->pnfs_error; |
| 196 | INIT_WORK(&hdr->task.u.tk_work, bl_read_cleanup); |
| 197 | schedule_work(&hdr->task.u.tk_work); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 200 | static enum pnfs_try_status |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 201 | bl_read_pagelist(struct nfs_pgio_header *header) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 202 | { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 203 | struct pnfs_block_layout *bl = BLK_LSEG2EXT(header->lseg); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 204 | struct bio *bio = NULL; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 205 | struct pnfs_block_extent be; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 206 | sector_t isect, extent_length = 0; |
| 207 | struct parallel_io *par; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 208 | loff_t f_offset = header->args.offset; |
| 209 | size_t bytes_left = header->args.count; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 210 | unsigned int pg_offset, pg_len; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 211 | struct page **pages = header->args.pages; |
| 212 | int pg_index = header->args.pgbase >> PAGE_CACHE_SHIFT; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 213 | const bool is_dio = (header->dreq != NULL); |
Christoph Hellwig | be98fd0 | 2014-08-21 11:09:28 -0500 | [diff] [blame] | 214 | struct blk_plug plug; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 215 | int i; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 216 | |
Trond Myklebust | 6f00866 | 2012-03-20 14:12:46 -0400 | [diff] [blame] | 217 | dprintk("%s enter nr_pages %u offset %lld count %u\n", __func__, |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 218 | header->page_array.npages, f_offset, |
| 219 | (unsigned int)header->args.count); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 220 | |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 221 | par = alloc_parallel(header); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 222 | if (!par) |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 223 | return PNFS_NOT_ATTEMPTED; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 224 | par->pnfs_callback = bl_end_par_io_read; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 225 | |
Christoph Hellwig | be98fd0 | 2014-08-21 11:09:28 -0500 | [diff] [blame] | 226 | blk_start_plug(&plug); |
| 227 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 228 | isect = (sector_t) (f_offset >> SECTOR_SHIFT); |
| 229 | /* Code assumes extents are page-aligned */ |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 230 | for (i = pg_index; i < header->page_array.npages; i++) { |
Christoph Hellwig | 921b81a | 2014-08-21 11:09:29 -0500 | [diff] [blame] | 231 | if (extent_length <= 0) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 232 | /* We've used up the previous extent */ |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 233 | bio = bl_submit_bio(READ, bio); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 234 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 235 | /* Get the next one */ |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 236 | if (!ext_tree_lookup(bl, isect, &be, false)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 237 | header->pnfs_error = -EIO; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 238 | goto out; |
| 239 | } |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 240 | extent_length = be.be_length - (isect - be.be_f_offset); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 241 | } |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 242 | |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 243 | pg_offset = f_offset & ~PAGE_CACHE_MASK; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 244 | if (is_dio) { |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 245 | if (pg_offset + bytes_left > PAGE_CACHE_SIZE) |
| 246 | pg_len = PAGE_CACHE_SIZE - pg_offset; |
| 247 | else |
| 248 | pg_len = bytes_left; |
| 249 | |
| 250 | f_offset += pg_len; |
| 251 | bytes_left -= pg_len; |
| 252 | isect += (pg_offset >> SECTOR_SHIFT); |
Christoph Hellwig | 921b81a | 2014-08-21 11:09:29 -0500 | [diff] [blame] | 253 | extent_length -= (pg_offset >> SECTOR_SHIFT); |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 254 | } else { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 255 | BUG_ON(pg_offset != 0); |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 256 | pg_len = PAGE_CACHE_SIZE; |
| 257 | } |
| 258 | |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 259 | if (is_hole(&be)) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 260 | bio = bl_submit_bio(READ, bio); |
| 261 | /* Fill hole w/ zeroes w/o accessing device */ |
| 262 | dprintk("%s Zeroing page for hole\n", __func__); |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 263 | zero_user_segment(pages[i], pg_offset, pg_len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 264 | } else { |
Weston Andros Adamson | 823b0c9 | 2014-06-09 11:48:34 -0400 | [diff] [blame] | 265 | bio = do_add_page_to_bio(bio, |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 266 | header->page_array.npages - i, |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 267 | READ, |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 268 | isect, pages[i], &be, |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 269 | bl_end_io_read, par, |
| 270 | pg_offset, pg_len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 271 | if (IS_ERR(bio)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 272 | header->pnfs_error = PTR_ERR(bio); |
Peng Tao | e6d05a7 | 2011-09-22 21:50:16 -0400 | [diff] [blame] | 273 | bio = NULL; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 274 | goto out; |
| 275 | } |
| 276 | } |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 277 | isect += (pg_len >> SECTOR_SHIFT); |
Christoph Hellwig | 921b81a | 2014-08-21 11:09:29 -0500 | [diff] [blame] | 278 | extent_length -= (pg_len >> SECTOR_SHIFT); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 279 | } |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 280 | if ((isect << SECTOR_SHIFT) >= header->inode->i_size) { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 281 | header->res.eof = 1; |
| 282 | header->res.count = header->inode->i_size - header->args.offset; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 283 | } else { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 284 | header->res.count = (isect << SECTOR_SHIFT) - header->args.offset; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 285 | } |
| 286 | out: |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 287 | bl_submit_bio(READ, bio); |
Christoph Hellwig | be98fd0 | 2014-08-21 11:09:28 -0500 | [diff] [blame] | 288 | blk_finish_plug(&plug); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 289 | put_parallel(par); |
| 290 | return PNFS_ATTEMPTED; |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 293 | static void bl_end_io_write(struct bio *bio, int err) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 294 | { |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 295 | struct parallel_io *par = bio->bi_private; |
| 296 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 297 | struct nfs_pgio_header *header = par->data; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 298 | |
| 299 | if (!uptodate) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 300 | if (!header->pnfs_error) |
| 301 | header->pnfs_error = -EIO; |
| 302 | pnfs_set_lo_fail(header->lseg); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 303 | } |
| 304 | bio_put(bio); |
| 305 | put_parallel(par); |
| 306 | } |
| 307 | |
| 308 | /* Function scheduled for call during bl_end_par_io_write, |
| 309 | * it marks sectors as written and extends the commitlist. |
| 310 | */ |
| 311 | static void bl_write_cleanup(struct work_struct *work) |
| 312 | { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 313 | struct rpc_task *task = container_of(work, struct rpc_task, u.tk_work); |
| 314 | struct nfs_pgio_header *hdr = |
| 315 | container_of(task, struct nfs_pgio_header, task); |
| 316 | |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 317 | dprintk("%s enter\n", __func__); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 318 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 319 | if (likely(!hdr->pnfs_error)) { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 320 | struct pnfs_block_layout *bl = BLK_LSEG2EXT(hdr->lseg); |
| 321 | u64 start = hdr->args.offset & (loff_t)PAGE_CACHE_MASK; |
| 322 | u64 end = (hdr->args.offset + hdr->args.count + |
| 323 | PAGE_CACHE_SIZE - 1) & (loff_t)PAGE_CACHE_MASK; |
| 324 | |
| 325 | ext_tree_mark_written(bl, start >> SECTOR_SHIFT, |
| 326 | (end - start) >> SECTOR_SHIFT); |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 327 | } |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 328 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 329 | pnfs_ld_write_done(hdr); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /* Called when last of bios associated with a bl_write_pagelist call finishes */ |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 333 | static void bl_end_par_io_write(void *data) |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 334 | { |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 335 | struct nfs_pgio_header *hdr = data; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 336 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 337 | hdr->task.tk_status = hdr->pnfs_error; |
Weston Andros Adamson | c65e625 | 2014-06-09 11:48:36 -0400 | [diff] [blame] | 338 | hdr->verf.committed = NFS_FILE_SYNC; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 339 | INIT_WORK(&hdr->task.u.tk_work, bl_write_cleanup); |
| 340 | schedule_work(&hdr->task.u.tk_work); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static enum pnfs_try_status |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 344 | bl_write_pagelist(struct nfs_pgio_header *header, int sync) |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 345 | { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 346 | struct pnfs_block_layout *bl = BLK_LSEG2EXT(header->lseg); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 347 | struct bio *bio = NULL; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 348 | struct pnfs_block_extent be; |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 349 | sector_t isect, extent_length = 0; |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 350 | struct parallel_io *par = NULL; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 351 | loff_t offset = header->args.offset; |
| 352 | size_t count = header->args.count; |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 353 | struct page **pages = header->args.pages; |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 354 | int pg_index = pg_index = header->args.pgbase >> PAGE_CACHE_SHIFT; |
Christoph Hellwig | be98fd0 | 2014-08-21 11:09:28 -0500 | [diff] [blame] | 355 | struct blk_plug plug; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 356 | int i; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 357 | |
| 358 | dprintk("%s enter, %Zu@%lld\n", __func__, count, offset); |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 359 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 360 | /* At this point, header->page_aray is a (sequential) list of nfs_pages. |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 361 | * We want to write each, and if there is an error set pnfs_error |
| 362 | * to have it redone using nfs. |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 363 | */ |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 364 | par = alloc_parallel(header); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 365 | if (!par) |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 366 | return PNFS_NOT_ATTEMPTED; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 367 | par->pnfs_callback = bl_end_par_io_write; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 368 | |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 369 | blk_start_plug(&plug); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 370 | |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 371 | /* we always write out the whole page */ |
| 372 | offset = offset & (loff_t)PAGE_CACHE_MASK; |
| 373 | isect = offset >> SECTOR_SHIFT; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 374 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 375 | for (i = pg_index; i < header->page_array.npages; i++) { |
Christoph Hellwig | 921b81a | 2014-08-21 11:09:29 -0500 | [diff] [blame] | 376 | if (extent_length <= 0) { |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 377 | /* We've used up the previous extent */ |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 378 | bio = bl_submit_bio(WRITE, bio); |
| 379 | /* Get the next one */ |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 380 | if (!ext_tree_lookup(bl, isect, &be, true)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 381 | header->pnfs_error = -EINVAL; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 382 | goto out; |
| 383 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 384 | |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 385 | extent_length = be.be_length - (isect - be.be_f_offset); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 386 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 387 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 388 | bio = do_add_page_to_bio(bio, header->page_array.npages - i, |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 389 | WRITE, isect, pages[i], &be, |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 390 | bl_end_io_write, par, |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 391 | 0, PAGE_CACHE_SIZE); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 392 | if (IS_ERR(bio)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 393 | header->pnfs_error = PTR_ERR(bio); |
Peng Tao | e6d05a7 | 2011-09-22 21:50:16 -0400 | [diff] [blame] | 394 | bio = NULL; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 395 | goto out; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 396 | } |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 397 | offset += PAGE_CACHE_SIZE; |
| 398 | count -= PAGE_CACHE_SIZE; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 399 | isect += PAGE_CACHE_SECTORS; |
| 400 | extent_length -= PAGE_CACHE_SECTORS; |
| 401 | } |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 402 | |
Weston Andros Adamson | d45f60c | 2014-06-09 11:48:35 -0400 | [diff] [blame] | 403 | header->res.count = header->args.count; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 404 | out: |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 405 | bl_submit_bio(WRITE, bio); |
Christoph Hellwig | be98fd0 | 2014-08-21 11:09:28 -0500 | [diff] [blame] | 406 | blk_finish_plug(&plug); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 407 | put_parallel(par); |
| 408 | return PNFS_ATTEMPTED; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void bl_free_layout_hdr(struct pnfs_layout_hdr *lo) |
| 412 | { |
| 413 | struct pnfs_block_layout *bl = BLK_LO2EXT(lo); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 414 | int err; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 415 | |
| 416 | dprintk("%s enter\n", __func__); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 417 | |
| 418 | err = ext_tree_remove(bl, true, 0, LLONG_MAX); |
| 419 | WARN_ON(err); |
| 420 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 421 | kfree(bl); |
| 422 | } |
| 423 | |
| 424 | static struct pnfs_layout_hdr *bl_alloc_layout_hdr(struct inode *inode, |
| 425 | gfp_t gfp_flags) |
| 426 | { |
| 427 | struct pnfs_block_layout *bl; |
| 428 | |
| 429 | dprintk("%s enter\n", __func__); |
| 430 | bl = kzalloc(sizeof(*bl), gfp_flags); |
| 431 | if (!bl) |
| 432 | return NULL; |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 433 | |
| 434 | bl->bl_ext_rw = RB_ROOT; |
| 435 | bl->bl_ext_ro = RB_ROOT; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 436 | spin_lock_init(&bl->bl_ext_lock); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 437 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 438 | return &bl->bl_layout; |
| 439 | } |
| 440 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 441 | static void bl_free_lseg(struct pnfs_layout_segment *lseg) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 442 | { |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 443 | dprintk("%s enter\n", __func__); |
| 444 | kfree(lseg); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 447 | /* We pretty much ignore lseg, and store all data layout wide, so we |
| 448 | * can correctly merge. |
| 449 | */ |
| 450 | static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, |
| 451 | struct nfs4_layoutget_res *lgr, |
| 452 | gfp_t gfp_flags) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 453 | { |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 454 | struct pnfs_layout_segment *lseg; |
| 455 | int status; |
| 456 | |
| 457 | dprintk("%s enter\n", __func__); |
| 458 | lseg = kzalloc(sizeof(*lseg), gfp_flags); |
| 459 | if (!lseg) |
| 460 | return ERR_PTR(-ENOMEM); |
| 461 | status = nfs4_blk_process_layoutget(lo, lgr, gfp_flags); |
| 462 | if (status) { |
| 463 | /* We don't want to call the full-blown bl_free_lseg, |
| 464 | * since on error extents were not touched. |
| 465 | */ |
| 466 | kfree(lseg); |
| 467 | return ERR_PTR(status); |
| 468 | } |
| 469 | return lseg; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | static void |
Christoph Hellwig | 71d5b76 | 2014-09-10 08:23:35 -0700 | [diff] [blame^] | 473 | bl_return_range(struct pnfs_layout_hdr *lo, |
| 474 | struct pnfs_layout_range *range) |
| 475 | { |
| 476 | struct pnfs_block_layout *bl = BLK_LO2EXT(lo); |
| 477 | sector_t offset = range->offset >> SECTOR_SHIFT, end; |
| 478 | int err; |
| 479 | |
| 480 | if (range->offset % 8) { |
| 481 | dprintk("%s: offset %lld not block size aligned\n", |
| 482 | __func__, range->offset); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | if (range->length != NFS4_MAX_UINT64) { |
| 487 | if (range->length % 8) { |
| 488 | dprintk("%s: length %lld not block size aligned\n", |
| 489 | __func__, range->length); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | end = offset + (range->length >> SECTOR_SHIFT); |
| 494 | } else { |
| 495 | end = round_down(NFS4_MAX_UINT64, PAGE_SIZE); |
| 496 | } |
| 497 | |
| 498 | err = ext_tree_remove(bl, range->iomode & IOMODE_RW, offset, end); |
| 499 | } |
| 500 | |
| 501 | static void |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 502 | bl_encode_layoutcommit(struct pnfs_layout_hdr *lo, struct xdr_stream *xdr, |
| 503 | const struct nfs4_layoutcommit_args *arg) |
| 504 | { |
Fred Isaman | 90ace12 | 2011-07-30 20:52:51 -0400 | [diff] [blame] | 505 | dprintk("%s enter\n", __func__); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 506 | ext_tree_encode_commit(BLK_LO2EXT(lo), xdr); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static void |
| 510 | bl_cleanup_layoutcommit(struct nfs4_layoutcommit_data *lcdata) |
| 511 | { |
Fred Isaman | b2be781 | 2011-07-30 20:52:52 -0400 | [diff] [blame] | 512 | struct pnfs_layout_hdr *lo = NFS_I(lcdata->args.inode)->layout; |
| 513 | |
| 514 | dprintk("%s enter\n", __func__); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 515 | ext_tree_mark_committed(BLK_LO2EXT(lo), lcdata->res.status); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 518 | static void free_blk_mountid(struct block_mount_id *mid) |
| 519 | { |
| 520 | if (mid) { |
Peng Tao | 93a3844 | 2012-01-12 23:18:47 +0800 | [diff] [blame] | 521 | struct pnfs_block_dev *dev, *tmp; |
| 522 | |
| 523 | /* No need to take bm_lock as we are last user freeing bm_devlist */ |
| 524 | list_for_each_entry_safe(dev, tmp, &mid->bm_devlist, bm_node) { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 525 | list_del(&dev->bm_node); |
| 526 | bl_free_block_dev(dev); |
| 527 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 528 | kfree(mid); |
| 529 | } |
| 530 | } |
| 531 | |
Trond Myklebust | 78e4e05 | 2012-09-18 21:02:29 -0400 | [diff] [blame] | 532 | /* This is mostly copied from the filelayout_get_device_info function. |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 533 | * It seems much of this should be at the generic pnfs level. |
| 534 | */ |
| 535 | static struct pnfs_block_dev * |
| 536 | nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh, |
| 537 | struct nfs4_deviceid *d_id) |
| 538 | { |
| 539 | struct pnfs_device *dev; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 540 | struct pnfs_block_dev *rv; |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 541 | u32 max_resp_sz; |
| 542 | int max_pages; |
| 543 | struct page **pages = NULL; |
| 544 | int i, rc; |
| 545 | |
| 546 | /* |
| 547 | * Use the session max response size as the basis for setting |
| 548 | * GETDEVICEINFO's maxcount |
| 549 | */ |
| 550 | max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
Jim Rees | 10bd295 | 2012-04-09 22:33:39 -0400 | [diff] [blame] | 551 | max_pages = nfs_page_array_len(0, max_resp_sz); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 552 | dprintk("%s max_resp_sz %u max_pages %d\n", |
| 553 | __func__, max_resp_sz, max_pages); |
| 554 | |
| 555 | dev = kmalloc(sizeof(*dev), GFP_NOFS); |
| 556 | if (!dev) { |
| 557 | dprintk("%s kmalloc failed\n", __func__); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 558 | return ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 559 | } |
| 560 | |
Fabian Frederick | f15b504 | 2014-06-25 20:26:21 +0200 | [diff] [blame] | 561 | pages = kcalloc(max_pages, sizeof(struct page *), GFP_NOFS); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 562 | if (pages == NULL) { |
| 563 | kfree(dev); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 564 | return ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 565 | } |
| 566 | for (i = 0; i < max_pages; i++) { |
| 567 | pages[i] = alloc_page(GFP_NOFS); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 568 | if (!pages[i]) { |
| 569 | rv = ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 570 | goto out_free; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 571 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | memcpy(&dev->dev_id, d_id, sizeof(*d_id)); |
| 575 | dev->layout_type = LAYOUT_BLOCK_VOLUME; |
| 576 | dev->pages = pages; |
| 577 | dev->pgbase = 0; |
| 578 | dev->pglen = PAGE_SIZE * max_pages; |
| 579 | dev->mincount = 0; |
Andy Adamson | 968fe25 | 2013-06-25 19:02:54 -0400 | [diff] [blame] | 580 | dev->maxcount = max_resp_sz - nfs41_maxgetdevinfo_overhead; |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 581 | |
| 582 | dprintk("%s: dev_id: %s\n", __func__, dev->dev_id.data); |
Trond Myklebust | cd5875f | 2013-05-20 11:42:54 -0400 | [diff] [blame] | 583 | rc = nfs4_proc_getdeviceinfo(server, dev, NULL); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 584 | dprintk("%s getdevice info returns %d\n", __func__, rc); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 585 | if (rc) { |
| 586 | rv = ERR_PTR(rc); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 587 | goto out_free; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 588 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 589 | |
| 590 | rv = nfs4_blk_decode_device(server, dev); |
| 591 | out_free: |
| 592 | for (i = 0; i < max_pages; i++) |
| 593 | __free_page(pages[i]); |
| 594 | kfree(pages); |
| 595 | kfree(dev); |
| 596 | return rv; |
| 597 | } |
| 598 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 599 | static int |
| 600 | bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh) |
| 601 | { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 602 | struct block_mount_id *b_mt_id = NULL; |
| 603 | struct pnfs_devicelist *dlist = NULL; |
| 604 | struct pnfs_block_dev *bdev; |
| 605 | LIST_HEAD(block_disklist); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 606 | int status, i; |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 607 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 608 | dprintk("%s enter\n", __func__); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 609 | |
| 610 | if (server->pnfs_blksize == 0) { |
| 611 | dprintk("%s Server did not return blksize\n", __func__); |
| 612 | return -EINVAL; |
| 613 | } |
Christoph Hellwig | e3aaf7f | 2014-08-21 11:09:26 -0500 | [diff] [blame] | 614 | if (server->pnfs_blksize > PAGE_SIZE) { |
| 615 | printk(KERN_ERR "%s: pNFS blksize %d not supported.\n", |
| 616 | __func__, server->pnfs_blksize); |
| 617 | return -EINVAL; |
| 618 | } |
| 619 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 620 | b_mt_id = kzalloc(sizeof(struct block_mount_id), GFP_NOFS); |
| 621 | if (!b_mt_id) { |
| 622 | status = -ENOMEM; |
| 623 | goto out_error; |
| 624 | } |
| 625 | /* Initialize nfs4 block layout mount id */ |
| 626 | spin_lock_init(&b_mt_id->bm_lock); |
| 627 | INIT_LIST_HEAD(&b_mt_id->bm_devlist); |
| 628 | |
| 629 | dlist = kmalloc(sizeof(struct pnfs_devicelist), GFP_NOFS); |
| 630 | if (!dlist) { |
| 631 | status = -ENOMEM; |
| 632 | goto out_error; |
| 633 | } |
| 634 | dlist->eof = 0; |
| 635 | while (!dlist->eof) { |
| 636 | status = nfs4_proc_getdevicelist(server, fh, dlist); |
| 637 | if (status) |
| 638 | goto out_error; |
| 639 | dprintk("%s GETDEVICELIST numdevs=%i, eof=%i\n", |
| 640 | __func__, dlist->num_devs, dlist->eof); |
| 641 | for (i = 0; i < dlist->num_devs; i++) { |
| 642 | bdev = nfs4_blk_get_deviceinfo(server, fh, |
| 643 | &dlist->dev_id[i]); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 644 | if (IS_ERR(bdev)) { |
| 645 | status = PTR_ERR(bdev); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 646 | goto out_error; |
| 647 | } |
| 648 | spin_lock(&b_mt_id->bm_lock); |
| 649 | list_add(&bdev->bm_node, &b_mt_id->bm_devlist); |
| 650 | spin_unlock(&b_mt_id->bm_lock); |
| 651 | } |
| 652 | } |
| 653 | dprintk("%s SUCCESS\n", __func__); |
| 654 | server->pnfs_ld_data = b_mt_id; |
| 655 | |
| 656 | out_return: |
| 657 | kfree(dlist); |
| 658 | return status; |
| 659 | |
| 660 | out_error: |
| 661 | free_blk_mountid(b_mt_id); |
| 662 | goto out_return; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | static int |
| 666 | bl_clear_layoutdriver(struct nfs_server *server) |
| 667 | { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 668 | struct block_mount_id *b_mt_id = server->pnfs_ld_data; |
| 669 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 670 | dprintk("%s enter\n", __func__); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 671 | free_blk_mountid(b_mt_id); |
| 672 | dprintk("%s RETURNS\n", __func__); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 673 | return 0; |
| 674 | } |
| 675 | |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 676 | static bool |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 677 | is_aligned_req(struct nfs_pageio_descriptor *pgio, |
| 678 | struct nfs_page *req, unsigned int alignment) |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 679 | { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 680 | /* |
| 681 | * Always accept buffered writes, higher layers take care of the |
| 682 | * right alignment. |
| 683 | */ |
| 684 | if (pgio->pg_dreq == NULL) |
| 685 | return true; |
| 686 | |
| 687 | if (!IS_ALIGNED(req->wb_offset, alignment)) |
| 688 | return false; |
| 689 | |
| 690 | if (IS_ALIGNED(req->wb_bytes, alignment)) |
| 691 | return true; |
| 692 | |
| 693 | if (req_offset(req) + req->wb_bytes == i_size_read(pgio->pg_inode)) { |
| 694 | /* |
| 695 | * If the write goes up to the inode size, just write |
| 696 | * the full page. Data past the inode size is |
| 697 | * guaranteed to be zeroed by the higher level client |
| 698 | * code, and this behaviour is mandated by RFC 5663 |
| 699 | * section 2.3.2. |
| 700 | */ |
| 701 | return true; |
| 702 | } |
| 703 | |
| 704 | return false; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static void |
| 708 | bl_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 709 | { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 710 | if (!is_aligned_req(pgio, req, SECTOR_SIZE)) { |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 711 | nfs_pageio_reset_read_mds(pgio); |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
| 715 | pnfs_generic_pg_init_read(pgio, req); |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 716 | } |
| 717 | |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 718 | /* |
| 719 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number |
| 720 | * of bytes (maximum @req->wb_bytes) that can be coalesced. |
| 721 | */ |
| 722 | static size_t |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 723 | bl_pg_test_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 724 | struct nfs_page *req) |
| 725 | { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 726 | if (!is_aligned_req(pgio, req, SECTOR_SIZE)) |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 727 | return 0; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 728 | return pnfs_generic_pg_test(pgio, prev, req); |
| 729 | } |
| 730 | |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 731 | /* |
| 732 | * Return the number of contiguous bytes for a given inode |
| 733 | * starting at page frame idx. |
| 734 | */ |
| 735 | static u64 pnfs_num_cont_bytes(struct inode *inode, pgoff_t idx) |
| 736 | { |
| 737 | struct address_space *mapping = inode->i_mapping; |
| 738 | pgoff_t end; |
| 739 | |
| 740 | /* Optimize common case that writes from 0 to end of file */ |
| 741 | end = DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE); |
| 742 | if (end != NFS_I(inode)->npages) { |
| 743 | rcu_read_lock(); |
Johannes Weiner | e7b563b | 2014-04-03 14:47:44 -0700 | [diff] [blame] | 744 | end = page_cache_next_hole(mapping, idx + 1, ULONG_MAX); |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 745 | rcu_read_unlock(); |
| 746 | } |
| 747 | |
| 748 | if (!end) |
| 749 | return i_size_read(inode) - (idx << PAGE_CACHE_SHIFT); |
| 750 | else |
| 751 | return (end - idx) << PAGE_CACHE_SHIFT; |
| 752 | } |
| 753 | |
Trond Myklebust | 6f018ef | 2012-10-02 08:29:14 -0700 | [diff] [blame] | 754 | static void |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 755 | bl_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 756 | { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 757 | u64 wb_size; |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 758 | |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 759 | if (!is_aligned_req(pgio, req, PAGE_SIZE)) { |
| 760 | nfs_pageio_reset_write_mds(pgio); |
| 761 | return; |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame] | 762 | } |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 763 | |
| 764 | if (pgio->pg_dreq == NULL) |
| 765 | wb_size = pnfs_num_cont_bytes(pgio->pg_inode, |
| 766 | req->wb_index); |
| 767 | else |
| 768 | wb_size = nfs_dreq_bytes_left(pgio->pg_dreq); |
| 769 | |
| 770 | pnfs_generic_pg_init_write(pgio, req, wb_size); |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 771 | } |
| 772 | |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 773 | /* |
| 774 | * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number |
| 775 | * of bytes (maximum @req->wb_bytes) that can be coalesced. |
| 776 | */ |
| 777 | static size_t |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 778 | bl_pg_test_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 779 | struct nfs_page *req) |
| 780 | { |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 781 | if (!is_aligned_req(pgio, req, PAGE_SIZE)) |
Weston Andros Adamson | b4fdac1 | 2014-05-15 11:56:43 -0400 | [diff] [blame] | 782 | return 0; |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 783 | return pnfs_generic_pg_test(pgio, prev, req); |
| 784 | } |
| 785 | |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 786 | static const struct nfs_pageio_ops bl_pg_read_ops = { |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 787 | .pg_init = bl_pg_init_read, |
| 788 | .pg_test = bl_pg_test_read, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 789 | .pg_doio = pnfs_generic_pg_readpages, |
| 790 | }; |
| 791 | |
| 792 | static const struct nfs_pageio_ops bl_pg_write_ops = { |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 793 | .pg_init = bl_pg_init_write, |
| 794 | .pg_test = bl_pg_test_write, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 795 | .pg_doio = pnfs_generic_pg_writepages, |
| 796 | }; |
| 797 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 798 | static struct pnfs_layoutdriver_type blocklayout_type = { |
| 799 | .id = LAYOUT_BLOCK_VOLUME, |
| 800 | .name = "LAYOUT_BLOCK_VOLUME", |
fanchaoting | 5a12cca | 2013-02-04 21:15:02 +0800 | [diff] [blame] | 801 | .owner = THIS_MODULE, |
Christoph Hellwig | 3a6fd1f | 2014-09-10 08:23:32 -0700 | [diff] [blame] | 802 | .flags = PNFS_READ_WHOLE_PAGE, |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 803 | .read_pagelist = bl_read_pagelist, |
| 804 | .write_pagelist = bl_write_pagelist, |
| 805 | .alloc_layout_hdr = bl_alloc_layout_hdr, |
| 806 | .free_layout_hdr = bl_free_layout_hdr, |
| 807 | .alloc_lseg = bl_alloc_lseg, |
| 808 | .free_lseg = bl_free_lseg, |
Christoph Hellwig | 71d5b76 | 2014-09-10 08:23:35 -0700 | [diff] [blame^] | 809 | .return_range = bl_return_range, |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 810 | .encode_layoutcommit = bl_encode_layoutcommit, |
| 811 | .cleanup_layoutcommit = bl_cleanup_layoutcommit, |
| 812 | .set_layoutdriver = bl_set_layoutdriver, |
| 813 | .clear_layoutdriver = bl_clear_layoutdriver, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 814 | .pg_read_ops = &bl_pg_read_ops, |
| 815 | .pg_write_ops = &bl_pg_write_ops, |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 816 | }; |
| 817 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 818 | static const struct rpc_pipe_ops bl_upcall_ops = { |
Peng Tao | c122515 | 2011-09-22 21:50:10 -0400 | [diff] [blame] | 819 | .upcall = rpc_pipe_generic_upcall, |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 820 | .downcall = bl_pipe_downcall, |
| 821 | .destroy_msg = bl_pipe_destroy_msg, |
| 822 | }; |
| 823 | |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 824 | static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb, |
| 825 | struct rpc_pipe *pipe) |
| 826 | { |
| 827 | struct dentry *dir, *dentry; |
| 828 | |
| 829 | dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME); |
| 830 | if (dir == NULL) |
| 831 | return ERR_PTR(-ENOENT); |
| 832 | dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe); |
| 833 | dput(dir); |
| 834 | return dentry; |
| 835 | } |
| 836 | |
| 837 | static void nfs4blocklayout_unregister_sb(struct super_block *sb, |
| 838 | struct rpc_pipe *pipe) |
| 839 | { |
| 840 | if (pipe->dentry) |
| 841 | rpc_unlink(pipe->dentry); |
| 842 | } |
| 843 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 844 | static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, |
| 845 | void *ptr) |
| 846 | { |
| 847 | struct super_block *sb = ptr; |
| 848 | struct net *net = sb->s_fs_info; |
| 849 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 850 | struct dentry *dentry; |
| 851 | int ret = 0; |
| 852 | |
| 853 | if (!try_module_get(THIS_MODULE)) |
| 854 | return 0; |
| 855 | |
| 856 | if (nn->bl_device_pipe == NULL) { |
| 857 | module_put(THIS_MODULE); |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | switch (event) { |
| 862 | case RPC_PIPEFS_MOUNT: |
| 863 | dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe); |
| 864 | if (IS_ERR(dentry)) { |
| 865 | ret = PTR_ERR(dentry); |
| 866 | break; |
| 867 | } |
| 868 | nn->bl_device_pipe->dentry = dentry; |
| 869 | break; |
| 870 | case RPC_PIPEFS_UMOUNT: |
| 871 | if (nn->bl_device_pipe->dentry) |
| 872 | nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe); |
| 873 | break; |
| 874 | default: |
| 875 | ret = -ENOTSUPP; |
| 876 | break; |
| 877 | } |
| 878 | module_put(THIS_MODULE); |
| 879 | return ret; |
| 880 | } |
| 881 | |
| 882 | static struct notifier_block nfs4blocklayout_block = { |
| 883 | .notifier_call = rpc_pipefs_event, |
| 884 | }; |
| 885 | |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 886 | static struct dentry *nfs4blocklayout_register_net(struct net *net, |
| 887 | struct rpc_pipe *pipe) |
| 888 | { |
| 889 | struct super_block *pipefs_sb; |
| 890 | struct dentry *dentry; |
| 891 | |
| 892 | pipefs_sb = rpc_get_sb_net(net); |
| 893 | if (!pipefs_sb) |
Stanislav Kinsbursky | 2561d61 | 2012-01-10 17:04:40 +0400 | [diff] [blame] | 894 | return NULL; |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 895 | dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe); |
| 896 | rpc_put_sb_net(net); |
| 897 | return dentry; |
| 898 | } |
| 899 | |
| 900 | static void nfs4blocklayout_unregister_net(struct net *net, |
| 901 | struct rpc_pipe *pipe) |
| 902 | { |
| 903 | struct super_block *pipefs_sb; |
| 904 | |
| 905 | pipefs_sb = rpc_get_sb_net(net); |
| 906 | if (pipefs_sb) { |
| 907 | nfs4blocklayout_unregister_sb(pipefs_sb, pipe); |
| 908 | rpc_put_sb_net(net); |
| 909 | } |
| 910 | } |
| 911 | |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 912 | static int nfs4blocklayout_net_init(struct net *net) |
| 913 | { |
| 914 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 915 | struct dentry *dentry; |
| 916 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 917 | init_waitqueue_head(&nn->bl_wq); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 918 | nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0); |
| 919 | if (IS_ERR(nn->bl_device_pipe)) |
| 920 | return PTR_ERR(nn->bl_device_pipe); |
| 921 | dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe); |
| 922 | if (IS_ERR(dentry)) { |
| 923 | rpc_destroy_pipe_data(nn->bl_device_pipe); |
| 924 | return PTR_ERR(dentry); |
| 925 | } |
| 926 | nn->bl_device_pipe->dentry = dentry; |
| 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | static void nfs4blocklayout_net_exit(struct net *net) |
| 931 | { |
| 932 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 933 | |
| 934 | nfs4blocklayout_unregister_net(net, nn->bl_device_pipe); |
| 935 | rpc_destroy_pipe_data(nn->bl_device_pipe); |
| 936 | nn->bl_device_pipe = NULL; |
| 937 | } |
| 938 | |
| 939 | static struct pernet_operations nfs4blocklayout_net_ops = { |
| 940 | .init = nfs4blocklayout_net_init, |
| 941 | .exit = nfs4blocklayout_net_exit, |
| 942 | }; |
| 943 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 944 | static int __init nfs4blocklayout_init(void) |
| 945 | { |
| 946 | int ret; |
| 947 | |
| 948 | dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__); |
| 949 | |
| 950 | ret = pnfs_register_layoutdriver(&blocklayout_type); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 951 | if (ret) |
| 952 | goto out; |
| 953 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 954 | ret = rpc_pipefs_notifier_register(&nfs4blocklayout_block); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 955 | if (ret) |
| 956 | goto out_remove; |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 957 | ret = register_pernet_subsys(&nfs4blocklayout_net_ops); |
| 958 | if (ret) |
| 959 | goto out_notifier; |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 960 | out: |
| 961 | return ret; |
| 962 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 963 | out_notifier: |
| 964 | rpc_pipefs_notifier_unregister(&nfs4blocklayout_block); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 965 | out_remove: |
| 966 | pnfs_unregister_layoutdriver(&blocklayout_type); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 967 | return ret; |
| 968 | } |
| 969 | |
| 970 | static void __exit nfs4blocklayout_exit(void) |
| 971 | { |
| 972 | dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n", |
| 973 | __func__); |
| 974 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 975 | rpc_pipefs_notifier_unregister(&nfs4blocklayout_block); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 976 | unregister_pernet_subsys(&nfs4blocklayout_net_ops); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 977 | pnfs_unregister_layoutdriver(&blocklayout_type); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | MODULE_ALIAS("nfs-layouttype4-3"); |
| 981 | |
| 982 | module_init(nfs4blocklayout_init); |
| 983 | module_exit(nfs4blocklayout_exit); |