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 */ |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 38 | #include <linux/buffer_head.h> /* various write calls */ |
Heiko Carstens | 88c9e42 | 2011-08-02 09:57:35 +0200 | [diff] [blame] | 39 | #include <linux/prefetch.h> |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame^] | 40 | #include <linux/pagevec.h> |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 41 | |
Jim Rees | 10bd295 | 2012-04-09 22:33:39 -0400 | [diff] [blame] | 42 | #include "../pnfs.h" |
| 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 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 52 | static void print_page(struct page *page) |
| 53 | { |
| 54 | dprintk("PRINTPAGE page %p\n", page); |
| 55 | dprintk(" PagePrivate %d\n", PagePrivate(page)); |
| 56 | dprintk(" PageUptodate %d\n", PageUptodate(page)); |
| 57 | dprintk(" PageError %d\n", PageError(page)); |
| 58 | dprintk(" PageDirty %d\n", PageDirty(page)); |
| 59 | dprintk(" PageReferenced %d\n", PageReferenced(page)); |
| 60 | dprintk(" PageLocked %d\n", PageLocked(page)); |
| 61 | dprintk(" PageWriteback %d\n", PageWriteback(page)); |
| 62 | dprintk(" PageMappedToDisk %d\n", PageMappedToDisk(page)); |
| 63 | dprintk("\n"); |
| 64 | } |
| 65 | |
| 66 | /* Given the be associated with isect, determine if page data needs to be |
| 67 | * initialized. |
| 68 | */ |
| 69 | static int is_hole(struct pnfs_block_extent *be, sector_t isect) |
| 70 | { |
| 71 | if (be->be_state == PNFS_BLOCK_NONE_DATA) |
| 72 | return 1; |
| 73 | else if (be->be_state != PNFS_BLOCK_INVALID_DATA) |
| 74 | return 0; |
| 75 | else |
| 76 | return !bl_is_sector_init(be->be_inval, isect); |
| 77 | } |
| 78 | |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 79 | /* Given the be associated with isect, determine if page data can be |
| 80 | * written to disk. |
| 81 | */ |
| 82 | static int is_writable(struct pnfs_block_extent *be, sector_t isect) |
| 83 | { |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 84 | return (be->be_state == PNFS_BLOCK_READWRITE_DATA || |
| 85 | be->be_state == PNFS_BLOCK_INVALID_DATA); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 88 | /* The data we are handed might be spread across several bios. We need |
| 89 | * to track when the last one is finished. |
| 90 | */ |
| 91 | struct parallel_io { |
| 92 | struct kref refcnt; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 93 | void (*pnfs_callback) (void *data, int num_se); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 94 | void *data; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 95 | int bse_count; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static inline struct parallel_io *alloc_parallel(void *data) |
| 99 | { |
| 100 | struct parallel_io *rv; |
| 101 | |
| 102 | rv = kmalloc(sizeof(*rv), GFP_NOFS); |
| 103 | if (rv) { |
| 104 | rv->data = data; |
| 105 | kref_init(&rv->refcnt); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 106 | rv->bse_count = 0; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 107 | } |
| 108 | return rv; |
| 109 | } |
| 110 | |
| 111 | static inline void get_parallel(struct parallel_io *p) |
| 112 | { |
| 113 | kref_get(&p->refcnt); |
| 114 | } |
| 115 | |
| 116 | static void destroy_parallel(struct kref *kref) |
| 117 | { |
| 118 | struct parallel_io *p = container_of(kref, struct parallel_io, refcnt); |
| 119 | |
| 120 | dprintk("%s enter\n", __func__); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 121 | p->pnfs_callback(p->data, p->bse_count); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 122 | kfree(p); |
| 123 | } |
| 124 | |
| 125 | static inline void put_parallel(struct parallel_io *p) |
| 126 | { |
| 127 | kref_put(&p->refcnt, destroy_parallel); |
| 128 | } |
| 129 | |
| 130 | static struct bio * |
| 131 | bl_submit_bio(int rw, struct bio *bio) |
| 132 | { |
| 133 | if (bio) { |
| 134 | get_parallel(bio->bi_private); |
| 135 | dprintk("%s submitting %s bio %u@%llu\n", __func__, |
| 136 | rw == READ ? "read" : "write", |
| 137 | bio->bi_size, (unsigned long long)bio->bi_sector); |
| 138 | submit_bio(rw, bio); |
| 139 | } |
| 140 | return NULL; |
| 141 | } |
| 142 | |
| 143 | static struct bio *bl_alloc_init_bio(int npg, sector_t isect, |
| 144 | struct pnfs_block_extent *be, |
| 145 | void (*end_io)(struct bio *, int err), |
| 146 | struct parallel_io *par) |
| 147 | { |
| 148 | struct bio *bio; |
| 149 | |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 150 | npg = min(npg, BIO_MAX_PAGES); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 151 | bio = bio_alloc(GFP_NOIO, npg); |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 152 | if (!bio && (current->flags & PF_MEMALLOC)) { |
| 153 | while (!bio && (npg /= 2)) |
| 154 | bio = bio_alloc(GFP_NOIO, npg); |
| 155 | } |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 156 | |
Peng Tao | 74a6eeb | 2012-01-12 23:18:48 +0800 | [diff] [blame] | 157 | if (bio) { |
| 158 | bio->bi_sector = isect - be->be_f_offset + be->be_v_offset; |
| 159 | bio->bi_bdev = be->be_mdev; |
| 160 | bio->bi_end_io = end_io; |
| 161 | bio->bi_private = par; |
| 162 | } |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 163 | return bio; |
| 164 | } |
| 165 | |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 166 | 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] | 167 | sector_t isect, struct page *page, |
| 168 | struct pnfs_block_extent *be, |
| 169 | void (*end_io)(struct bio *, int err), |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 170 | struct parallel_io *par, |
| 171 | unsigned int offset, int len) |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 172 | { |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 173 | isect = isect + (offset >> SECTOR_SHIFT); |
| 174 | dprintk("%s: npg %d rw %d isect %llu offset %u len %d\n", __func__, |
| 175 | npg, rw, (unsigned long long)isect, offset, len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 176 | retry: |
| 177 | if (!bio) { |
| 178 | bio = bl_alloc_init_bio(npg, isect, be, end_io, par); |
| 179 | if (!bio) |
| 180 | return ERR_PTR(-ENOMEM); |
| 181 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 182 | if (bio_add_page(bio, page, len, offset) < len) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 183 | bio = bl_submit_bio(rw, bio); |
| 184 | goto retry; |
| 185 | } |
| 186 | return bio; |
| 187 | } |
| 188 | |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 189 | static struct bio *bl_add_page_to_bio(struct bio *bio, int npg, int rw, |
| 190 | sector_t isect, struct page *page, |
| 191 | struct pnfs_block_extent *be, |
| 192 | void (*end_io)(struct bio *, int err), |
| 193 | struct parallel_io *par) |
| 194 | { |
| 195 | return do_add_page_to_bio(bio, npg, rw, isect, page, be, |
| 196 | end_io, par, 0, PAGE_CACHE_SIZE); |
| 197 | } |
| 198 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 199 | /* This is basically copied from mpage_end_io_read */ |
| 200 | static void bl_end_io_read(struct bio *bio, int err) |
| 201 | { |
| 202 | struct parallel_io *par = bio->bi_private; |
| 203 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 204 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 205 | |
| 206 | do { |
| 207 | struct page *page = bvec->bv_page; |
| 208 | |
| 209 | if (--bvec >= bio->bi_io_vec) |
| 210 | prefetchw(&bvec->bv_page->flags); |
| 211 | if (uptodate) |
| 212 | SetPageUptodate(page); |
| 213 | } while (bvec >= bio->bi_io_vec); |
| 214 | if (!uptodate) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 215 | struct nfs_read_data *rdata = par->data; |
| 216 | struct nfs_pgio_header *header = rdata->header; |
| 217 | |
| 218 | if (!header->pnfs_error) |
| 219 | header->pnfs_error = -EIO; |
| 220 | pnfs_set_lo_fail(header->lseg); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 221 | } |
| 222 | bio_put(bio); |
| 223 | put_parallel(par); |
| 224 | } |
| 225 | |
| 226 | static void bl_read_cleanup(struct work_struct *work) |
| 227 | { |
| 228 | struct rpc_task *task; |
| 229 | struct nfs_read_data *rdata; |
| 230 | dprintk("%s enter\n", __func__); |
| 231 | task = container_of(work, struct rpc_task, u.tk_work); |
| 232 | rdata = container_of(task, struct nfs_read_data, task); |
| 233 | pnfs_ld_read_done(rdata); |
| 234 | } |
| 235 | |
| 236 | static void |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 237 | bl_end_par_io_read(void *data, int unused) |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 238 | { |
| 239 | struct nfs_read_data *rdata = data; |
| 240 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 241 | rdata->task.tk_status = rdata->header->pnfs_error; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 242 | INIT_WORK(&rdata->task.u.tk_work, bl_read_cleanup); |
| 243 | schedule_work(&rdata->task.u.tk_work); |
| 244 | } |
| 245 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 246 | static enum pnfs_try_status |
| 247 | bl_read_pagelist(struct nfs_read_data *rdata) |
| 248 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 249 | struct nfs_pgio_header *header = rdata->header; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 250 | int i, hole; |
| 251 | struct bio *bio = NULL; |
| 252 | struct pnfs_block_extent *be = NULL, *cow_read = NULL; |
| 253 | sector_t isect, extent_length = 0; |
| 254 | struct parallel_io *par; |
| 255 | loff_t f_offset = rdata->args.offset; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 256 | size_t bytes_left = rdata->args.count; |
| 257 | unsigned int pg_offset, pg_len; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 258 | struct page **pages = rdata->args.pages; |
| 259 | int pg_index = rdata->args.pgbase >> PAGE_CACHE_SHIFT; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 260 | const bool is_dio = (header->dreq != NULL); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 261 | |
Trond Myklebust | 6f00866 | 2012-03-20 14:12:46 -0400 | [diff] [blame] | 262 | dprintk("%s enter nr_pages %u offset %lld count %u\n", __func__, |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 263 | rdata->pages.npages, f_offset, (unsigned int)rdata->args.count); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 264 | |
| 265 | par = alloc_parallel(rdata); |
| 266 | if (!par) |
| 267 | goto use_mds; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 268 | par->pnfs_callback = bl_end_par_io_read; |
| 269 | /* At this point, we can no longer jump to use_mds */ |
| 270 | |
| 271 | isect = (sector_t) (f_offset >> SECTOR_SHIFT); |
| 272 | /* Code assumes extents are page-aligned */ |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 273 | for (i = pg_index; i < rdata->pages.npages; i++) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 274 | if (!extent_length) { |
| 275 | /* We've used up the previous extent */ |
| 276 | bl_put_extent(be); |
| 277 | bl_put_extent(cow_read); |
| 278 | bio = bl_submit_bio(READ, bio); |
| 279 | /* Get the next one */ |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 280 | be = bl_find_get_extent(BLK_LSEG2EXT(header->lseg), |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 281 | isect, &cow_read); |
| 282 | if (!be) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 283 | header->pnfs_error = -EIO; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 284 | goto out; |
| 285 | } |
| 286 | extent_length = be->be_length - |
| 287 | (isect - be->be_f_offset); |
| 288 | if (cow_read) { |
| 289 | sector_t cow_length = cow_read->be_length - |
| 290 | (isect - cow_read->be_f_offset); |
| 291 | extent_length = min(extent_length, cow_length); |
| 292 | } |
| 293 | } |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 294 | |
| 295 | if (is_dio) { |
| 296 | pg_offset = f_offset & ~PAGE_CACHE_MASK; |
| 297 | if (pg_offset + bytes_left > PAGE_CACHE_SIZE) |
| 298 | pg_len = PAGE_CACHE_SIZE - pg_offset; |
| 299 | else |
| 300 | pg_len = bytes_left; |
| 301 | |
| 302 | f_offset += pg_len; |
| 303 | bytes_left -= pg_len; |
| 304 | isect += (pg_offset >> SECTOR_SHIFT); |
| 305 | } else { |
| 306 | pg_offset = 0; |
| 307 | pg_len = PAGE_CACHE_SIZE; |
| 308 | } |
| 309 | |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 310 | hole = is_hole(be, isect); |
| 311 | if (hole && !cow_read) { |
| 312 | bio = bl_submit_bio(READ, bio); |
| 313 | /* Fill hole w/ zeroes w/o accessing device */ |
| 314 | dprintk("%s Zeroing page for hole\n", __func__); |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 315 | zero_user_segment(pages[i], pg_offset, pg_len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 316 | print_page(pages[i]); |
| 317 | SetPageUptodate(pages[i]); |
| 318 | } else { |
| 319 | struct pnfs_block_extent *be_read; |
| 320 | |
| 321 | be_read = (hole && cow_read) ? cow_read : be; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 322 | bio = do_add_page_to_bio(bio, rdata->pages.npages - i, |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 323 | READ, |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 324 | isect, pages[i], be_read, |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 325 | bl_end_io_read, par, |
| 326 | pg_offset, pg_len); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 327 | if (IS_ERR(bio)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 328 | header->pnfs_error = PTR_ERR(bio); |
Peng Tao | e6d05a7 | 2011-09-22 21:50:16 -0400 | [diff] [blame] | 329 | bio = NULL; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 330 | goto out; |
| 331 | } |
| 332 | } |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 333 | isect += (pg_len >> SECTOR_SHIFT); |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 334 | extent_length -= PAGE_CACHE_SECTORS; |
| 335 | } |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 336 | if ((isect << SECTOR_SHIFT) >= header->inode->i_size) { |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 337 | rdata->res.eof = 1; |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 338 | rdata->res.count = header->inode->i_size - rdata->args.offset; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 339 | } else { |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 340 | rdata->res.count = (isect << SECTOR_SHIFT) - rdata->args.offset; |
Fred Isaman | 9549ec0 | 2011-07-30 20:52:53 -0400 | [diff] [blame] | 341 | } |
| 342 | out: |
| 343 | bl_put_extent(be); |
| 344 | bl_put_extent(cow_read); |
| 345 | bl_submit_bio(READ, bio); |
| 346 | put_parallel(par); |
| 347 | return PNFS_ATTEMPTED; |
| 348 | |
| 349 | use_mds: |
| 350 | dprintk("Giving up and using normal NFS\n"); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 351 | return PNFS_NOT_ATTEMPTED; |
| 352 | } |
| 353 | |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 354 | static void mark_extents_written(struct pnfs_block_layout *bl, |
| 355 | __u64 offset, __u32 count) |
| 356 | { |
| 357 | sector_t isect, end; |
| 358 | struct pnfs_block_extent *be; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 359 | struct pnfs_block_short_extent *se; |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 360 | |
| 361 | dprintk("%s(%llu, %u)\n", __func__, offset, count); |
| 362 | if (count == 0) |
| 363 | return; |
| 364 | isect = (offset & (long)(PAGE_CACHE_MASK)) >> SECTOR_SHIFT; |
| 365 | end = (offset + count + PAGE_CACHE_SIZE - 1) & (long)(PAGE_CACHE_MASK); |
| 366 | end >>= SECTOR_SHIFT; |
| 367 | while (isect < end) { |
| 368 | sector_t len; |
| 369 | be = bl_find_get_extent(bl, isect, NULL); |
| 370 | BUG_ON(!be); /* FIXME */ |
| 371 | len = min(end, be->be_f_offset + be->be_length) - isect; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 372 | if (be->be_state == PNFS_BLOCK_INVALID_DATA) { |
| 373 | se = bl_pop_one_short_extent(be->be_inval); |
| 374 | BUG_ON(!se); |
| 375 | bl_mark_for_commit(be, isect, len, se); |
| 376 | } |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 377 | isect += len; |
| 378 | bl_put_extent(be); |
| 379 | } |
| 380 | } |
| 381 | |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 382 | static void bl_end_io_write_zero(struct bio *bio, int err) |
| 383 | { |
| 384 | struct parallel_io *par = bio->bi_private; |
| 385 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
| 386 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 387 | |
| 388 | do { |
| 389 | struct page *page = bvec->bv_page; |
| 390 | |
| 391 | if (--bvec >= bio->bi_io_vec) |
| 392 | prefetchw(&bvec->bv_page->flags); |
| 393 | /* This is the zeroing page we added */ |
| 394 | end_page_writeback(page); |
| 395 | page_cache_release(page); |
| 396 | } while (bvec >= bio->bi_io_vec); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 397 | |
| 398 | if (unlikely(!uptodate)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 399 | struct nfs_write_data *data = par->data; |
| 400 | struct nfs_pgio_header *header = data->header; |
| 401 | |
| 402 | if (!header->pnfs_error) |
| 403 | header->pnfs_error = -EIO; |
| 404 | pnfs_set_lo_fail(header->lseg); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 405 | } |
| 406 | bio_put(bio); |
| 407 | put_parallel(par); |
| 408 | } |
| 409 | |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 410 | static void bl_end_io_write(struct bio *bio, int err) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 411 | { |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 412 | struct parallel_io *par = bio->bi_private; |
| 413 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 414 | struct nfs_write_data *data = par->data; |
| 415 | struct nfs_pgio_header *header = data->header; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 416 | |
| 417 | if (!uptodate) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 418 | if (!header->pnfs_error) |
| 419 | header->pnfs_error = -EIO; |
| 420 | pnfs_set_lo_fail(header->lseg); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 421 | } |
| 422 | bio_put(bio); |
| 423 | put_parallel(par); |
| 424 | } |
| 425 | |
| 426 | /* Function scheduled for call during bl_end_par_io_write, |
| 427 | * it marks sectors as written and extends the commitlist. |
| 428 | */ |
| 429 | static void bl_write_cleanup(struct work_struct *work) |
| 430 | { |
| 431 | struct rpc_task *task; |
| 432 | struct nfs_write_data *wdata; |
| 433 | dprintk("%s enter\n", __func__); |
| 434 | task = container_of(work, struct rpc_task, u.tk_work); |
| 435 | wdata = container_of(task, struct nfs_write_data, task); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 436 | if (likely(!wdata->header->pnfs_error)) { |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 437 | /* Marks for LAYOUTCOMMIT */ |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 438 | mark_extents_written(BLK_LSEG2EXT(wdata->header->lseg), |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 439 | wdata->args.offset, wdata->args.count); |
| 440 | } |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 441 | pnfs_ld_write_done(wdata); |
| 442 | } |
| 443 | |
| 444 | /* Called when last of bios associated with a bl_write_pagelist call finishes */ |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 445 | static void bl_end_par_io_write(void *data, int num_se) |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 446 | { |
| 447 | struct nfs_write_data *wdata = data; |
| 448 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 449 | if (unlikely(wdata->header->pnfs_error)) { |
| 450 | bl_free_short_extents(&BLK_LSEG2EXT(wdata->header->lseg)->bl_inval, |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 451 | num_se); |
| 452 | } |
| 453 | |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 454 | wdata->task.tk_status = wdata->header->pnfs_error; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 455 | wdata->verf.committed = NFS_FILE_SYNC; |
| 456 | INIT_WORK(&wdata->task.u.tk_work, bl_write_cleanup); |
| 457 | schedule_work(&wdata->task.u.tk_work); |
| 458 | } |
| 459 | |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 460 | /* FIXME STUB - mark intersection of layout and page as bad, so is not |
| 461 | * used again. |
| 462 | */ |
| 463 | static void mark_bad_read(void) |
| 464 | { |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * map_block: map a requested I/0 block (isect) into an offset in the LVM |
| 470 | * block_device |
| 471 | */ |
| 472 | static void |
| 473 | map_block(struct buffer_head *bh, sector_t isect, struct pnfs_block_extent *be) |
| 474 | { |
| 475 | dprintk("%s enter be=%p\n", __func__, be); |
| 476 | |
| 477 | set_buffer_mapped(bh); |
| 478 | bh->b_bdev = be->be_mdev; |
| 479 | bh->b_blocknr = (isect - be->be_f_offset + be->be_v_offset) >> |
| 480 | (be->be_mdev->bd_inode->i_blkbits - SECTOR_SHIFT); |
| 481 | |
| 482 | dprintk("%s isect %llu, bh->b_blocknr %ld, using bsize %Zd\n", |
| 483 | __func__, (unsigned long long)isect, (long)bh->b_blocknr, |
| 484 | bh->b_size); |
| 485 | return; |
| 486 | } |
| 487 | |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 488 | static void |
| 489 | bl_read_single_end_io(struct bio *bio, int error) |
| 490 | { |
| 491 | struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; |
| 492 | struct page *page = bvec->bv_page; |
| 493 | |
| 494 | /* Only one page in bvec */ |
| 495 | unlock_page(page); |
| 496 | } |
| 497 | |
| 498 | static int |
| 499 | bl_do_readpage_sync(struct page *page, struct pnfs_block_extent *be, |
| 500 | unsigned int offset, unsigned int len) |
| 501 | { |
| 502 | struct bio *bio; |
| 503 | struct page *shadow_page; |
| 504 | sector_t isect; |
| 505 | char *kaddr, *kshadow_addr; |
| 506 | int ret = 0; |
| 507 | |
| 508 | dprintk("%s: offset %u len %u\n", __func__, offset, len); |
| 509 | |
| 510 | shadow_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); |
| 511 | if (shadow_page == NULL) |
| 512 | return -ENOMEM; |
| 513 | |
| 514 | bio = bio_alloc(GFP_NOIO, 1); |
| 515 | if (bio == NULL) |
| 516 | return -ENOMEM; |
| 517 | |
| 518 | isect = (page->index << PAGE_CACHE_SECTOR_SHIFT) + |
| 519 | (offset / SECTOR_SIZE); |
| 520 | |
| 521 | bio->bi_sector = isect - be->be_f_offset + be->be_v_offset; |
| 522 | bio->bi_bdev = be->be_mdev; |
| 523 | bio->bi_end_io = bl_read_single_end_io; |
| 524 | |
| 525 | lock_page(shadow_page); |
| 526 | if (bio_add_page(bio, shadow_page, |
| 527 | SECTOR_SIZE, round_down(offset, SECTOR_SIZE)) == 0) { |
| 528 | unlock_page(shadow_page); |
| 529 | bio_put(bio); |
| 530 | return -EIO; |
| 531 | } |
| 532 | |
| 533 | submit_bio(READ, bio); |
| 534 | wait_on_page_locked(shadow_page); |
| 535 | if (unlikely(!test_bit(BIO_UPTODATE, &bio->bi_flags))) { |
| 536 | ret = -EIO; |
| 537 | } else { |
| 538 | kaddr = kmap_atomic(page); |
| 539 | kshadow_addr = kmap_atomic(shadow_page); |
| 540 | memcpy(kaddr + offset, kshadow_addr + offset, len); |
| 541 | kunmap_atomic(kshadow_addr); |
| 542 | kunmap_atomic(kaddr); |
| 543 | } |
| 544 | __free_page(shadow_page); |
| 545 | bio_put(bio); |
| 546 | |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | static int |
| 551 | bl_read_partial_page_sync(struct page *page, struct pnfs_block_extent *be, |
| 552 | unsigned int dirty_offset, unsigned int dirty_len, |
| 553 | bool full_page) |
| 554 | { |
| 555 | int ret = 0; |
| 556 | unsigned int start, end; |
| 557 | |
| 558 | if (full_page) { |
| 559 | start = 0; |
| 560 | end = PAGE_CACHE_SIZE; |
| 561 | } else { |
| 562 | start = round_down(dirty_offset, SECTOR_SIZE); |
| 563 | end = round_up(dirty_offset + dirty_len, SECTOR_SIZE); |
| 564 | } |
| 565 | |
| 566 | dprintk("%s: offset %u len %d\n", __func__, dirty_offset, dirty_len); |
| 567 | if (!be) { |
| 568 | zero_user_segments(page, start, dirty_offset, |
| 569 | dirty_offset + dirty_len, end); |
| 570 | if (start == 0 && end == PAGE_CACHE_SIZE && |
| 571 | trylock_page(page)) { |
| 572 | SetPageUptodate(page); |
| 573 | unlock_page(page); |
| 574 | } |
| 575 | return ret; |
| 576 | } |
| 577 | |
| 578 | if (start != dirty_offset) |
| 579 | ret = bl_do_readpage_sync(page, be, start, dirty_offset - start); |
| 580 | |
| 581 | if (!ret && (dirty_offset + dirty_len < end)) |
| 582 | ret = bl_do_readpage_sync(page, be, dirty_offset + dirty_len, |
| 583 | end - dirty_offset - dirty_len); |
| 584 | |
| 585 | return ret; |
| 586 | } |
| 587 | |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 588 | /* Given an unmapped page, zero it or read in page for COW, page is locked |
| 589 | * by caller. |
| 590 | */ |
| 591 | static int |
| 592 | init_page_for_write(struct page *page, struct pnfs_block_extent *cow_read) |
| 593 | { |
| 594 | struct buffer_head *bh = NULL; |
| 595 | int ret = 0; |
| 596 | sector_t isect; |
| 597 | |
| 598 | dprintk("%s enter, %p\n", __func__, page); |
| 599 | BUG_ON(PageUptodate(page)); |
| 600 | if (!cow_read) { |
| 601 | zero_user_segment(page, 0, PAGE_SIZE); |
| 602 | SetPageUptodate(page); |
| 603 | goto cleanup; |
| 604 | } |
| 605 | |
| 606 | bh = alloc_page_buffers(page, PAGE_CACHE_SIZE, 0); |
| 607 | if (!bh) { |
| 608 | ret = -ENOMEM; |
| 609 | goto cleanup; |
| 610 | } |
| 611 | |
| 612 | isect = (sector_t) page->index << PAGE_CACHE_SECTOR_SHIFT; |
| 613 | map_block(bh, isect, cow_read); |
| 614 | if (!bh_uptodate_or_lock(bh)) |
| 615 | ret = bh_submit_read(bh); |
| 616 | if (ret) |
| 617 | goto cleanup; |
| 618 | SetPageUptodate(page); |
| 619 | |
| 620 | cleanup: |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 621 | if (bh) |
| 622 | free_buffer_head(bh); |
| 623 | if (ret) { |
| 624 | /* Need to mark layout with bad read...should now |
| 625 | * just use nfs4 for reads and writes. |
| 626 | */ |
| 627 | mark_bad_read(); |
| 628 | } |
| 629 | return ret; |
| 630 | } |
| 631 | |
Peng Tao | 72c5088 | 2012-01-12 23:18:42 +0800 | [diff] [blame] | 632 | /* Find or create a zeroing page marked being writeback. |
| 633 | * Return ERR_PTR on error, NULL to indicate skip this page and page itself |
| 634 | * to indicate write out. |
| 635 | */ |
| 636 | static struct page * |
| 637 | bl_find_get_zeroing_page(struct inode *inode, pgoff_t index, |
| 638 | struct pnfs_block_extent *cow_read) |
| 639 | { |
| 640 | struct page *page; |
| 641 | int locked = 0; |
| 642 | page = find_get_page(inode->i_mapping, index); |
| 643 | if (page) |
| 644 | goto check_page; |
| 645 | |
| 646 | page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); |
| 647 | if (unlikely(!page)) { |
| 648 | dprintk("%s oom\n", __func__); |
| 649 | return ERR_PTR(-ENOMEM); |
| 650 | } |
| 651 | locked = 1; |
| 652 | |
| 653 | check_page: |
| 654 | /* PageDirty: Other will write this out |
| 655 | * PageWriteback: Other is writing this out |
| 656 | * PageUptodate: It was read before |
| 657 | */ |
| 658 | if (PageDirty(page) || PageWriteback(page)) { |
| 659 | print_page(page); |
| 660 | if (locked) |
| 661 | unlock_page(page); |
| 662 | page_cache_release(page); |
| 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | if (!locked) { |
| 667 | lock_page(page); |
| 668 | locked = 1; |
| 669 | goto check_page; |
| 670 | } |
| 671 | if (!PageUptodate(page)) { |
| 672 | /* New page, readin or zero it */ |
| 673 | init_page_for_write(page, cow_read); |
| 674 | } |
| 675 | set_page_writeback(page); |
| 676 | unlock_page(page); |
| 677 | |
| 678 | return page; |
| 679 | } |
| 680 | |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 681 | static enum pnfs_try_status |
| 682 | bl_write_pagelist(struct nfs_write_data *wdata, int sync) |
| 683 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 684 | struct nfs_pgio_header *header = wdata->header; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 685 | int i, ret, npg_zero, pg_index, last = 0; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 686 | struct bio *bio = NULL; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 687 | struct pnfs_block_extent *be = NULL, *cow_read = NULL; |
| 688 | sector_t isect, last_isect = 0, extent_length = 0; |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 689 | struct parallel_io *par = NULL; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 690 | loff_t offset = wdata->args.offset; |
| 691 | size_t count = wdata->args.count; |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 692 | unsigned int pg_offset, pg_len, saved_len; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 693 | struct page **pages = wdata->args.pages; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 694 | struct page *page; |
| 695 | pgoff_t index; |
| 696 | u64 temp; |
| 697 | int npg_per_block = |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 698 | NFS_SERVER(header->inode)->pnfs_blksize >> PAGE_CACHE_SHIFT; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 699 | |
| 700 | dprintk("%s enter, %Zu@%lld\n", __func__, count, offset); |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 701 | |
| 702 | if (header->dreq != NULL && |
| 703 | (!IS_ALIGNED(offset, NFS_SERVER(header->inode)->pnfs_blksize) || |
| 704 | !IS_ALIGNED(count, NFS_SERVER(header->inode)->pnfs_blksize))) { |
| 705 | dprintk("pnfsblock nonblock aligned DIO writes. Resend MDS\n"); |
| 706 | goto out_mds; |
| 707 | } |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 708 | /* At this point, wdata->pages is a (sequential) list of nfs_pages. |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 709 | * We want to write each, and if there is an error set pnfs_error |
| 710 | * to have it redone using nfs. |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 711 | */ |
| 712 | par = alloc_parallel(wdata); |
| 713 | if (!par) |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 714 | goto out_mds; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 715 | par->pnfs_callback = bl_end_par_io_write; |
| 716 | /* At this point, have to be more careful with error handling */ |
| 717 | |
| 718 | isect = (sector_t) ((offset & (long)PAGE_CACHE_MASK) >> SECTOR_SHIFT); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 719 | be = bl_find_get_extent(BLK_LSEG2EXT(header->lseg), isect, &cow_read); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 720 | if (!be || !is_writable(be, isect)) { |
| 721 | dprintk("%s no matching extents!\n", __func__); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 722 | goto out_mds; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /* First page inside INVALID extent */ |
| 726 | if (be->be_state == PNFS_BLOCK_INVALID_DATA) { |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 727 | if (likely(!bl_push_one_short_extent(be->be_inval))) |
| 728 | par->bse_count++; |
| 729 | else |
| 730 | goto out_mds; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 731 | temp = offset >> PAGE_CACHE_SHIFT; |
| 732 | npg_zero = do_div(temp, npg_per_block); |
| 733 | isect = (sector_t) (((offset - npg_zero * PAGE_CACHE_SIZE) & |
| 734 | (long)PAGE_CACHE_MASK) >> SECTOR_SHIFT); |
| 735 | extent_length = be->be_length - (isect - be->be_f_offset); |
| 736 | |
| 737 | fill_invalid_ext: |
| 738 | dprintk("%s need to zero %d pages\n", __func__, npg_zero); |
| 739 | for (;npg_zero > 0; npg_zero--) { |
Peng Tao | 7542274 | 2011-09-22 21:50:17 -0400 | [diff] [blame] | 740 | if (bl_is_sector_init(be->be_inval, isect)) { |
| 741 | dprintk("isect %llu already init\n", |
| 742 | (unsigned long long)isect); |
| 743 | goto next_page; |
| 744 | } |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 745 | /* page ref released in bl_end_io_write_zero */ |
| 746 | index = isect >> PAGE_CACHE_SECTOR_SHIFT; |
| 747 | dprintk("%s zero %dth page: index %lu isect %llu\n", |
| 748 | __func__, npg_zero, index, |
| 749 | (unsigned long long)isect); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 750 | page = bl_find_get_zeroing_page(header->inode, index, |
Peng Tao | 72c5088 | 2012-01-12 23:18:42 +0800 | [diff] [blame] | 751 | cow_read); |
| 752 | if (unlikely(IS_ERR(page))) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 753 | header->pnfs_error = PTR_ERR(page); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 754 | goto out; |
Peng Tao | 72c5088 | 2012-01-12 23:18:42 +0800 | [diff] [blame] | 755 | } else if (page == NULL) |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 756 | goto next_page; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 757 | |
| 758 | ret = bl_mark_sectors_init(be->be_inval, isect, |
Peng Tao | 60c52e3 | 2012-01-12 23:18:40 +0800 | [diff] [blame] | 759 | PAGE_CACHE_SECTORS); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 760 | if (unlikely(ret)) { |
| 761 | dprintk("%s bl_mark_sectors_init fail %d\n", |
| 762 | __func__, ret); |
| 763 | end_page_writeback(page); |
| 764 | page_cache_release(page); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 765 | header->pnfs_error = ret; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 766 | goto out; |
| 767 | } |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 768 | if (likely(!bl_push_one_short_extent(be->be_inval))) |
| 769 | par->bse_count++; |
| 770 | else { |
| 771 | end_page_writeback(page); |
| 772 | page_cache_release(page); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 773 | header->pnfs_error = -ENOMEM; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 774 | goto out; |
| 775 | } |
| 776 | /* FIXME: This should be done in bi_end_io */ |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 777 | mark_extents_written(BLK_LSEG2EXT(header->lseg), |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 778 | page->index << PAGE_CACHE_SHIFT, |
| 779 | PAGE_CACHE_SIZE); |
| 780 | |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 781 | bio = bl_add_page_to_bio(bio, npg_zero, WRITE, |
| 782 | isect, page, be, |
| 783 | bl_end_io_write_zero, par); |
| 784 | if (IS_ERR(bio)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 785 | header->pnfs_error = PTR_ERR(bio); |
Peng Tao | e6d05a7 | 2011-09-22 21:50:16 -0400 | [diff] [blame] | 786 | bio = NULL; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 787 | goto out; |
| 788 | } |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 789 | next_page: |
| 790 | isect += PAGE_CACHE_SECTORS; |
| 791 | extent_length -= PAGE_CACHE_SECTORS; |
| 792 | } |
| 793 | if (last) |
| 794 | goto write_done; |
| 795 | } |
| 796 | bio = bl_submit_bio(WRITE, bio); |
| 797 | |
| 798 | /* Middle pages */ |
| 799 | pg_index = wdata->args.pgbase >> PAGE_CACHE_SHIFT; |
Fred Isaman | 30dd374 | 2012-04-20 14:47:45 -0400 | [diff] [blame] | 800 | for (i = pg_index; i < wdata->pages.npages; i++) { |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 801 | if (!extent_length) { |
| 802 | /* We've used up the previous extent */ |
| 803 | bl_put_extent(be); |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 804 | bl_put_extent(cow_read); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 805 | bio = bl_submit_bio(WRITE, bio); |
| 806 | /* Get the next one */ |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 807 | be = bl_find_get_extent(BLK_LSEG2EXT(header->lseg), |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 808 | isect, &cow_read); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 809 | if (!be || !is_writable(be, isect)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 810 | header->pnfs_error = -EINVAL; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 811 | goto out; |
| 812 | } |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 813 | if (be->be_state == PNFS_BLOCK_INVALID_DATA) { |
| 814 | if (likely(!bl_push_one_short_extent( |
| 815 | be->be_inval))) |
| 816 | par->bse_count++; |
| 817 | else { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 818 | header->pnfs_error = -ENOMEM; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 819 | goto out; |
| 820 | } |
| 821 | } |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 822 | extent_length = be->be_length - |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 823 | (isect - be->be_f_offset); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 824 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 825 | |
| 826 | dprintk("%s offset %lld count %Zu\n", __func__, offset, count); |
| 827 | pg_offset = offset & ~PAGE_CACHE_MASK; |
| 828 | if (pg_offset + count > PAGE_CACHE_SIZE) |
| 829 | pg_len = PAGE_CACHE_SIZE - pg_offset; |
| 830 | else |
| 831 | pg_len = count; |
| 832 | |
| 833 | saved_len = pg_len; |
| 834 | if (be->be_state == PNFS_BLOCK_INVALID_DATA && |
| 835 | !bl_is_sector_init(be->be_inval, isect)) { |
| 836 | ret = bl_read_partial_page_sync(pages[i], cow_read, |
| 837 | pg_offset, pg_len, true); |
| 838 | if (ret) { |
| 839 | dprintk("%s bl_read_partial_page_sync fail %d\n", |
| 840 | __func__, ret); |
| 841 | header->pnfs_error = ret; |
| 842 | goto out; |
| 843 | } |
| 844 | |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 845 | ret = bl_mark_sectors_init(be->be_inval, isect, |
Peng Tao | 60c52e3 | 2012-01-12 23:18:40 +0800 | [diff] [blame] | 846 | PAGE_CACHE_SECTORS); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 847 | if (unlikely(ret)) { |
| 848 | dprintk("%s bl_mark_sectors_init fail %d\n", |
| 849 | __func__, ret); |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 850 | header->pnfs_error = ret; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 851 | goto out; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 852 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 853 | |
| 854 | /* Expand to full page write */ |
| 855 | pg_offset = 0; |
| 856 | pg_len = PAGE_CACHE_SIZE; |
| 857 | } else if ((pg_offset & (SECTOR_SIZE - 1)) || |
| 858 | (pg_len & (SECTOR_SIZE - 1))){ |
| 859 | /* ahh, nasty case. We have to do sync full sector |
| 860 | * read-modify-write cycles. |
| 861 | */ |
| 862 | unsigned int saved_offset = pg_offset; |
| 863 | ret = bl_read_partial_page_sync(pages[i], be, pg_offset, |
| 864 | pg_len, false); |
| 865 | pg_offset = round_down(pg_offset, SECTOR_SIZE); |
| 866 | pg_len = round_up(saved_offset + pg_len, SECTOR_SIZE) |
| 867 | - pg_offset; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 868 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 869 | |
| 870 | |
| 871 | bio = do_add_page_to_bio(bio, wdata->pages.npages - i, WRITE, |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 872 | isect, pages[i], be, |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 873 | bl_end_io_write, par, |
| 874 | pg_offset, pg_len); |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 875 | if (IS_ERR(bio)) { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 876 | header->pnfs_error = PTR_ERR(bio); |
Peng Tao | e6d05a7 | 2011-09-22 21:50:16 -0400 | [diff] [blame] | 877 | bio = NULL; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 878 | goto out; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 879 | } |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 880 | offset += saved_len; |
| 881 | count -= saved_len; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 882 | isect += PAGE_CACHE_SECTORS; |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 883 | last_isect = isect; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 884 | extent_length -= PAGE_CACHE_SECTORS; |
| 885 | } |
Peng Tao | 71cdd40 | 2011-07-30 20:52:56 -0400 | [diff] [blame] | 886 | |
| 887 | /* Last page inside INVALID extent */ |
| 888 | if (be->be_state == PNFS_BLOCK_INVALID_DATA) { |
| 889 | bio = bl_submit_bio(WRITE, bio); |
| 890 | temp = last_isect >> PAGE_CACHE_SECTOR_SHIFT; |
| 891 | npg_zero = npg_per_block - do_div(temp, npg_per_block); |
| 892 | if (npg_zero < npg_per_block) { |
| 893 | last = 1; |
| 894 | goto fill_invalid_ext; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | write_done: |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 899 | wdata->res.count = wdata->args.count; |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 900 | out: |
| 901 | bl_put_extent(be); |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 902 | bl_put_extent(cow_read); |
Fred Isaman | 650e2d3 | 2011-07-30 20:52:54 -0400 | [diff] [blame] | 903 | bl_submit_bio(WRITE, bio); |
| 904 | put_parallel(par); |
| 905 | return PNFS_ATTEMPTED; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 906 | out_mds: |
| 907 | bl_put_extent(be); |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 908 | bl_put_extent(cow_read); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 909 | kfree(par); |
| 910 | return PNFS_NOT_ATTEMPTED; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 911 | } |
| 912 | |
Fred Isaman | 9e69296 | 2011-07-30 20:52:41 -0400 | [diff] [blame] | 913 | /* FIXME - range ignored */ |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 914 | static void |
Fred Isaman | 9e69296 | 2011-07-30 20:52:41 -0400 | [diff] [blame] | 915 | release_extents(struct pnfs_block_layout *bl, struct pnfs_layout_range *range) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 916 | { |
Fred Isaman | 9e69296 | 2011-07-30 20:52:41 -0400 | [diff] [blame] | 917 | int i; |
| 918 | struct pnfs_block_extent *be; |
| 919 | |
| 920 | spin_lock(&bl->bl_ext_lock); |
| 921 | for (i = 0; i < EXTENT_LISTS; i++) { |
| 922 | while (!list_empty(&bl->bl_extents[i])) { |
| 923 | be = list_first_entry(&bl->bl_extents[i], |
| 924 | struct pnfs_block_extent, |
| 925 | be_node); |
| 926 | list_del(&be->be_node); |
| 927 | bl_put_extent(be); |
| 928 | } |
| 929 | } |
| 930 | spin_unlock(&bl->bl_ext_lock); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 931 | } |
| 932 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 933 | static void |
| 934 | release_inval_marks(struct pnfs_inval_markings *marks) |
| 935 | { |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 936 | struct pnfs_inval_tracking *pos, *temp; |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 937 | struct pnfs_block_short_extent *se, *stemp; |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 938 | |
| 939 | list_for_each_entry_safe(pos, temp, &marks->im_tree.mtt_stub, it_link) { |
| 940 | list_del(&pos->it_link); |
| 941 | kfree(pos); |
| 942 | } |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 943 | |
| 944 | list_for_each_entry_safe(se, stemp, &marks->im_extents, bse_node) { |
| 945 | list_del(&se->bse_node); |
| 946 | kfree(se); |
| 947 | } |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 948 | return; |
| 949 | } |
| 950 | |
| 951 | static void bl_free_layout_hdr(struct pnfs_layout_hdr *lo) |
| 952 | { |
| 953 | struct pnfs_block_layout *bl = BLK_LO2EXT(lo); |
| 954 | |
| 955 | dprintk("%s enter\n", __func__); |
| 956 | release_extents(bl, NULL); |
| 957 | release_inval_marks(&bl->bl_inval); |
| 958 | kfree(bl); |
| 959 | } |
| 960 | |
| 961 | static struct pnfs_layout_hdr *bl_alloc_layout_hdr(struct inode *inode, |
| 962 | gfp_t gfp_flags) |
| 963 | { |
| 964 | struct pnfs_block_layout *bl; |
| 965 | |
| 966 | dprintk("%s enter\n", __func__); |
| 967 | bl = kzalloc(sizeof(*bl), gfp_flags); |
| 968 | if (!bl) |
| 969 | return NULL; |
| 970 | spin_lock_init(&bl->bl_ext_lock); |
| 971 | INIT_LIST_HEAD(&bl->bl_extents[0]); |
| 972 | INIT_LIST_HEAD(&bl->bl_extents[1]); |
| 973 | INIT_LIST_HEAD(&bl->bl_commit); |
| 974 | INIT_LIST_HEAD(&bl->bl_committing); |
| 975 | bl->bl_count = 0; |
| 976 | bl->bl_blocksize = NFS_SERVER(inode)->pnfs_blksize >> SECTOR_SHIFT; |
| 977 | BL_INIT_INVAL_MARKS(&bl->bl_inval, bl->bl_blocksize); |
| 978 | return &bl->bl_layout; |
| 979 | } |
| 980 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 981 | static void bl_free_lseg(struct pnfs_layout_segment *lseg) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 982 | { |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 983 | dprintk("%s enter\n", __func__); |
| 984 | kfree(lseg); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 987 | /* We pretty much ignore lseg, and store all data layout wide, so we |
| 988 | * can correctly merge. |
| 989 | */ |
| 990 | static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, |
| 991 | struct nfs4_layoutget_res *lgr, |
| 992 | gfp_t gfp_flags) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 993 | { |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 994 | struct pnfs_layout_segment *lseg; |
| 995 | int status; |
| 996 | |
| 997 | dprintk("%s enter\n", __func__); |
| 998 | lseg = kzalloc(sizeof(*lseg), gfp_flags); |
| 999 | if (!lseg) |
| 1000 | return ERR_PTR(-ENOMEM); |
| 1001 | status = nfs4_blk_process_layoutget(lo, lgr, gfp_flags); |
| 1002 | if (status) { |
| 1003 | /* We don't want to call the full-blown bl_free_lseg, |
| 1004 | * since on error extents were not touched. |
| 1005 | */ |
| 1006 | kfree(lseg); |
| 1007 | return ERR_PTR(status); |
| 1008 | } |
| 1009 | return lseg; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | static void |
| 1013 | bl_encode_layoutcommit(struct pnfs_layout_hdr *lo, struct xdr_stream *xdr, |
| 1014 | const struct nfs4_layoutcommit_args *arg) |
| 1015 | { |
Fred Isaman | 90ace12 | 2011-07-30 20:52:51 -0400 | [diff] [blame] | 1016 | dprintk("%s enter\n", __func__); |
| 1017 | encode_pnfs_block_layoutupdate(BLK_LO2EXT(lo), xdr, arg); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | bl_cleanup_layoutcommit(struct nfs4_layoutcommit_data *lcdata) |
| 1022 | { |
Fred Isaman | b2be781 | 2011-07-30 20:52:52 -0400 | [diff] [blame] | 1023 | struct pnfs_layout_hdr *lo = NFS_I(lcdata->args.inode)->layout; |
| 1024 | |
| 1025 | dprintk("%s enter\n", __func__); |
| 1026 | clean_pnfs_block_layoutupdate(BLK_LO2EXT(lo), &lcdata->args, lcdata->res.status); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1029 | static void free_blk_mountid(struct block_mount_id *mid) |
| 1030 | { |
| 1031 | if (mid) { |
Peng Tao | 93a3844 | 2012-01-12 23:18:47 +0800 | [diff] [blame] | 1032 | struct pnfs_block_dev *dev, *tmp; |
| 1033 | |
| 1034 | /* No need to take bm_lock as we are last user freeing bm_devlist */ |
| 1035 | list_for_each_entry_safe(dev, tmp, &mid->bm_devlist, bm_node) { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1036 | list_del(&dev->bm_node); |
| 1037 | bl_free_block_dev(dev); |
| 1038 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1039 | kfree(mid); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Trond Myklebust | 78e4e05 | 2012-09-18 21:02:29 -0400 | [diff] [blame] | 1043 | /* This is mostly copied from the filelayout_get_device_info function. |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1044 | * It seems much of this should be at the generic pnfs level. |
| 1045 | */ |
| 1046 | static struct pnfs_block_dev * |
| 1047 | nfs4_blk_get_deviceinfo(struct nfs_server *server, const struct nfs_fh *fh, |
| 1048 | struct nfs4_deviceid *d_id) |
| 1049 | { |
| 1050 | struct pnfs_device *dev; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1051 | struct pnfs_block_dev *rv; |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1052 | u32 max_resp_sz; |
| 1053 | int max_pages; |
| 1054 | struct page **pages = NULL; |
| 1055 | int i, rc; |
| 1056 | |
| 1057 | /* |
| 1058 | * Use the session max response size as the basis for setting |
| 1059 | * GETDEVICEINFO's maxcount |
| 1060 | */ |
| 1061 | 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] | 1062 | max_pages = nfs_page_array_len(0, max_resp_sz); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1063 | dprintk("%s max_resp_sz %u max_pages %d\n", |
| 1064 | __func__, max_resp_sz, max_pages); |
| 1065 | |
| 1066 | dev = kmalloc(sizeof(*dev), GFP_NOFS); |
| 1067 | if (!dev) { |
| 1068 | dprintk("%s kmalloc failed\n", __func__); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1069 | return ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | pages = kzalloc(max_pages * sizeof(struct page *), GFP_NOFS); |
| 1073 | if (pages == NULL) { |
| 1074 | kfree(dev); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1075 | return ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1076 | } |
| 1077 | for (i = 0; i < max_pages; i++) { |
| 1078 | pages[i] = alloc_page(GFP_NOFS); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1079 | if (!pages[i]) { |
| 1080 | rv = ERR_PTR(-ENOMEM); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1081 | goto out_free; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1082 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | memcpy(&dev->dev_id, d_id, sizeof(*d_id)); |
| 1086 | dev->layout_type = LAYOUT_BLOCK_VOLUME; |
| 1087 | dev->pages = pages; |
| 1088 | dev->pgbase = 0; |
| 1089 | dev->pglen = PAGE_SIZE * max_pages; |
| 1090 | dev->mincount = 0; |
| 1091 | |
| 1092 | dprintk("%s: dev_id: %s\n", __func__, dev->dev_id.data); |
| 1093 | rc = nfs4_proc_getdeviceinfo(server, dev); |
| 1094 | dprintk("%s getdevice info returns %d\n", __func__, rc); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1095 | if (rc) { |
| 1096 | rv = ERR_PTR(rc); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1097 | goto out_free; |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1098 | } |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1099 | |
| 1100 | rv = nfs4_blk_decode_device(server, dev); |
| 1101 | out_free: |
| 1102 | for (i = 0; i < max_pages; i++) |
| 1103 | __free_page(pages[i]); |
| 1104 | kfree(pages); |
| 1105 | kfree(dev); |
| 1106 | return rv; |
| 1107 | } |
| 1108 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1109 | static int |
| 1110 | bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh) |
| 1111 | { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1112 | struct block_mount_id *b_mt_id = NULL; |
| 1113 | struct pnfs_devicelist *dlist = NULL; |
| 1114 | struct pnfs_block_dev *bdev; |
| 1115 | LIST_HEAD(block_disklist); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1116 | int status, i; |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1117 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1118 | dprintk("%s enter\n", __func__); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1119 | |
| 1120 | if (server->pnfs_blksize == 0) { |
| 1121 | dprintk("%s Server did not return blksize\n", __func__); |
| 1122 | return -EINVAL; |
| 1123 | } |
| 1124 | b_mt_id = kzalloc(sizeof(struct block_mount_id), GFP_NOFS); |
| 1125 | if (!b_mt_id) { |
| 1126 | status = -ENOMEM; |
| 1127 | goto out_error; |
| 1128 | } |
| 1129 | /* Initialize nfs4 block layout mount id */ |
| 1130 | spin_lock_init(&b_mt_id->bm_lock); |
| 1131 | INIT_LIST_HEAD(&b_mt_id->bm_devlist); |
| 1132 | |
| 1133 | dlist = kmalloc(sizeof(struct pnfs_devicelist), GFP_NOFS); |
| 1134 | if (!dlist) { |
| 1135 | status = -ENOMEM; |
| 1136 | goto out_error; |
| 1137 | } |
| 1138 | dlist->eof = 0; |
| 1139 | while (!dlist->eof) { |
| 1140 | status = nfs4_proc_getdevicelist(server, fh, dlist); |
| 1141 | if (status) |
| 1142 | goto out_error; |
| 1143 | dprintk("%s GETDEVICELIST numdevs=%i, eof=%i\n", |
| 1144 | __func__, dlist->num_devs, dlist->eof); |
| 1145 | for (i = 0; i < dlist->num_devs; i++) { |
| 1146 | bdev = nfs4_blk_get_deviceinfo(server, fh, |
| 1147 | &dlist->dev_id[i]); |
Jim Rees | 516f2e2 | 2011-09-22 21:50:08 -0400 | [diff] [blame] | 1148 | if (IS_ERR(bdev)) { |
| 1149 | status = PTR_ERR(bdev); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1150 | goto out_error; |
| 1151 | } |
| 1152 | spin_lock(&b_mt_id->bm_lock); |
| 1153 | list_add(&bdev->bm_node, &b_mt_id->bm_devlist); |
| 1154 | spin_unlock(&b_mt_id->bm_lock); |
| 1155 | } |
| 1156 | } |
| 1157 | dprintk("%s SUCCESS\n", __func__); |
| 1158 | server->pnfs_ld_data = b_mt_id; |
| 1159 | |
| 1160 | out_return: |
| 1161 | kfree(dlist); |
| 1162 | return status; |
| 1163 | |
| 1164 | out_error: |
| 1165 | free_blk_mountid(b_mt_id); |
| 1166 | goto out_return; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | static int |
| 1170 | bl_clear_layoutdriver(struct nfs_server *server) |
| 1171 | { |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1172 | struct block_mount_id *b_mt_id = server->pnfs_ld_data; |
| 1173 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1174 | dprintk("%s enter\n", __func__); |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 1175 | free_blk_mountid(b_mt_id); |
| 1176 | dprintk("%s RETURNS\n", __func__); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 1180 | static bool |
| 1181 | is_aligned_req(struct nfs_page *req, unsigned int alignment) |
| 1182 | { |
| 1183 | return IS_ALIGNED(req->wb_offset, alignment) && |
| 1184 | IS_ALIGNED(req->wb_bytes, alignment); |
| 1185 | } |
| 1186 | |
| 1187 | static void |
| 1188 | bl_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1189 | { |
| 1190 | if (pgio->pg_dreq != NULL && |
| 1191 | !is_aligned_req(req, SECTOR_SIZE)) |
| 1192 | nfs_pageio_reset_read_mds(pgio); |
| 1193 | else |
| 1194 | pnfs_generic_pg_init_read(pgio, req); |
| 1195 | } |
| 1196 | |
| 1197 | static bool |
| 1198 | bl_pg_test_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 1199 | struct nfs_page *req) |
| 1200 | { |
| 1201 | if (pgio->pg_dreq != NULL && |
| 1202 | !is_aligned_req(req, SECTOR_SIZE)) |
| 1203 | return false; |
| 1204 | |
| 1205 | return pnfs_generic_pg_test(pgio, prev, req); |
| 1206 | } |
| 1207 | |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame^] | 1208 | /* |
| 1209 | * Return the number of contiguous bytes for a given inode |
| 1210 | * starting at page frame idx. |
| 1211 | */ |
| 1212 | static u64 pnfs_num_cont_bytes(struct inode *inode, pgoff_t idx) |
| 1213 | { |
| 1214 | struct address_space *mapping = inode->i_mapping; |
| 1215 | pgoff_t end; |
| 1216 | |
| 1217 | /* Optimize common case that writes from 0 to end of file */ |
| 1218 | end = DIV_ROUND_UP(i_size_read(inode), PAGE_CACHE_SIZE); |
| 1219 | if (end != NFS_I(inode)->npages) { |
| 1220 | rcu_read_lock(); |
| 1221 | end = radix_tree_next_hole(&mapping->page_tree, idx + 1, ULONG_MAX); |
| 1222 | rcu_read_unlock(); |
| 1223 | } |
| 1224 | |
| 1225 | if (!end) |
| 1226 | return i_size_read(inode) - (idx << PAGE_CACHE_SHIFT); |
| 1227 | else |
| 1228 | return (end - idx) << PAGE_CACHE_SHIFT; |
| 1229 | } |
| 1230 | |
Trond Myklebust | 6f018ef | 2012-10-02 08:29:14 -0700 | [diff] [blame] | 1231 | static void |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 1232 | bl_pg_init_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *req) |
| 1233 | { |
| 1234 | if (pgio->pg_dreq != NULL && |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame^] | 1235 | !is_aligned_req(req, PAGE_CACHE_SIZE)) { |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 1236 | nfs_pageio_reset_write_mds(pgio); |
Peng Tao | 6296556 | 2012-09-25 14:55:57 +0800 | [diff] [blame^] | 1237 | } else { |
| 1238 | u64 wb_size; |
| 1239 | if (pgio->pg_dreq == NULL) |
| 1240 | wb_size = pnfs_num_cont_bytes(pgio->pg_inode, |
| 1241 | req->wb_index); |
| 1242 | else |
| 1243 | wb_size = nfs_dreq_bytes_left(pgio->pg_dreq); |
| 1244 | |
| 1245 | pnfs_generic_pg_init_write(pgio, req, wb_size); |
| 1246 | } |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | static bool |
| 1250 | bl_pg_test_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, |
| 1251 | struct nfs_page *req) |
| 1252 | { |
| 1253 | if (pgio->pg_dreq != NULL && |
| 1254 | !is_aligned_req(req, PAGE_CACHE_SIZE)) |
| 1255 | return false; |
| 1256 | |
| 1257 | return pnfs_generic_pg_test(pgio, prev, req); |
| 1258 | } |
| 1259 | |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 1260 | static const struct nfs_pageio_ops bl_pg_read_ops = { |
Peng Tao | f742dc4 | 2012-08-24 00:27:52 +0800 | [diff] [blame] | 1261 | .pg_init = bl_pg_init_read, |
| 1262 | .pg_test = bl_pg_test_read, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 1263 | .pg_doio = pnfs_generic_pg_readpages, |
| 1264 | }; |
| 1265 | |
| 1266 | static const struct nfs_pageio_ops bl_pg_write_ops = { |
Peng Tao | 96c9eae | 2012-08-24 00:27:53 +0800 | [diff] [blame] | 1267 | .pg_init = bl_pg_init_write, |
| 1268 | .pg_test = bl_pg_test_write, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 1269 | .pg_doio = pnfs_generic_pg_writepages, |
| 1270 | }; |
| 1271 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1272 | static struct pnfs_layoutdriver_type blocklayout_type = { |
| 1273 | .id = LAYOUT_BLOCK_VOLUME, |
| 1274 | .name = "LAYOUT_BLOCK_VOLUME", |
| 1275 | .read_pagelist = bl_read_pagelist, |
| 1276 | .write_pagelist = bl_write_pagelist, |
| 1277 | .alloc_layout_hdr = bl_alloc_layout_hdr, |
| 1278 | .free_layout_hdr = bl_free_layout_hdr, |
| 1279 | .alloc_lseg = bl_alloc_lseg, |
| 1280 | .free_lseg = bl_free_lseg, |
| 1281 | .encode_layoutcommit = bl_encode_layoutcommit, |
| 1282 | .cleanup_layoutcommit = bl_cleanup_layoutcommit, |
| 1283 | .set_layoutdriver = bl_set_layoutdriver, |
| 1284 | .clear_layoutdriver = bl_clear_layoutdriver, |
Benny Halevy | e9643fe | 2011-07-30 20:52:40 -0400 | [diff] [blame] | 1285 | .pg_read_ops = &bl_pg_read_ops, |
| 1286 | .pg_write_ops = &bl_pg_write_ops, |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1287 | }; |
| 1288 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 1289 | static const struct rpc_pipe_ops bl_upcall_ops = { |
Peng Tao | c122515 | 2011-09-22 21:50:10 -0400 | [diff] [blame] | 1290 | .upcall = rpc_pipe_generic_upcall, |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 1291 | .downcall = bl_pipe_downcall, |
| 1292 | .destroy_msg = bl_pipe_destroy_msg, |
| 1293 | }; |
| 1294 | |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 1295 | static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb, |
| 1296 | struct rpc_pipe *pipe) |
| 1297 | { |
| 1298 | struct dentry *dir, *dentry; |
| 1299 | |
| 1300 | dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME); |
| 1301 | if (dir == NULL) |
| 1302 | return ERR_PTR(-ENOENT); |
| 1303 | dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe); |
| 1304 | dput(dir); |
| 1305 | return dentry; |
| 1306 | } |
| 1307 | |
| 1308 | static void nfs4blocklayout_unregister_sb(struct super_block *sb, |
| 1309 | struct rpc_pipe *pipe) |
| 1310 | { |
| 1311 | if (pipe->dentry) |
| 1312 | rpc_unlink(pipe->dentry); |
| 1313 | } |
| 1314 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 1315 | static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, |
| 1316 | void *ptr) |
| 1317 | { |
| 1318 | struct super_block *sb = ptr; |
| 1319 | struct net *net = sb->s_fs_info; |
| 1320 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1321 | struct dentry *dentry; |
| 1322 | int ret = 0; |
| 1323 | |
| 1324 | if (!try_module_get(THIS_MODULE)) |
| 1325 | return 0; |
| 1326 | |
| 1327 | if (nn->bl_device_pipe == NULL) { |
| 1328 | module_put(THIS_MODULE); |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
| 1332 | switch (event) { |
| 1333 | case RPC_PIPEFS_MOUNT: |
| 1334 | dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe); |
| 1335 | if (IS_ERR(dentry)) { |
| 1336 | ret = PTR_ERR(dentry); |
| 1337 | break; |
| 1338 | } |
| 1339 | nn->bl_device_pipe->dentry = dentry; |
| 1340 | break; |
| 1341 | case RPC_PIPEFS_UMOUNT: |
| 1342 | if (nn->bl_device_pipe->dentry) |
| 1343 | nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe); |
| 1344 | break; |
| 1345 | default: |
| 1346 | ret = -ENOTSUPP; |
| 1347 | break; |
| 1348 | } |
| 1349 | module_put(THIS_MODULE); |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
| 1353 | static struct notifier_block nfs4blocklayout_block = { |
| 1354 | .notifier_call = rpc_pipefs_event, |
| 1355 | }; |
| 1356 | |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 1357 | static struct dentry *nfs4blocklayout_register_net(struct net *net, |
| 1358 | struct rpc_pipe *pipe) |
| 1359 | { |
| 1360 | struct super_block *pipefs_sb; |
| 1361 | struct dentry *dentry; |
| 1362 | |
| 1363 | pipefs_sb = rpc_get_sb_net(net); |
| 1364 | if (!pipefs_sb) |
Stanislav Kinsbursky | 2561d61 | 2012-01-10 17:04:40 +0400 | [diff] [blame] | 1365 | return NULL; |
Stanislav Kinsbursky | 332dfab | 2012-01-10 17:04:16 +0400 | [diff] [blame] | 1366 | dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe); |
| 1367 | rpc_put_sb_net(net); |
| 1368 | return dentry; |
| 1369 | } |
| 1370 | |
| 1371 | static void nfs4blocklayout_unregister_net(struct net *net, |
| 1372 | struct rpc_pipe *pipe) |
| 1373 | { |
| 1374 | struct super_block *pipefs_sb; |
| 1375 | |
| 1376 | pipefs_sb = rpc_get_sb_net(net); |
| 1377 | if (pipefs_sb) { |
| 1378 | nfs4blocklayout_unregister_sb(pipefs_sb, pipe); |
| 1379 | rpc_put_sb_net(net); |
| 1380 | } |
| 1381 | } |
| 1382 | |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 1383 | static int nfs4blocklayout_net_init(struct net *net) |
| 1384 | { |
| 1385 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1386 | struct dentry *dentry; |
| 1387 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 1388 | init_waitqueue_head(&nn->bl_wq); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 1389 | nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0); |
| 1390 | if (IS_ERR(nn->bl_device_pipe)) |
| 1391 | return PTR_ERR(nn->bl_device_pipe); |
| 1392 | dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe); |
| 1393 | if (IS_ERR(dentry)) { |
| 1394 | rpc_destroy_pipe_data(nn->bl_device_pipe); |
| 1395 | return PTR_ERR(dentry); |
| 1396 | } |
| 1397 | nn->bl_device_pipe->dentry = dentry; |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
| 1401 | static void nfs4blocklayout_net_exit(struct net *net) |
| 1402 | { |
| 1403 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
| 1404 | |
| 1405 | nfs4blocklayout_unregister_net(net, nn->bl_device_pipe); |
| 1406 | rpc_destroy_pipe_data(nn->bl_device_pipe); |
| 1407 | nn->bl_device_pipe = NULL; |
| 1408 | } |
| 1409 | |
| 1410 | static struct pernet_operations nfs4blocklayout_net_ops = { |
| 1411 | .init = nfs4blocklayout_net_init, |
| 1412 | .exit = nfs4blocklayout_net_exit, |
| 1413 | }; |
| 1414 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1415 | static int __init nfs4blocklayout_init(void) |
| 1416 | { |
| 1417 | int ret; |
| 1418 | |
| 1419 | dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__); |
| 1420 | |
| 1421 | ret = pnfs_register_layoutdriver(&blocklayout_type); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 1422 | if (ret) |
| 1423 | goto out; |
| 1424 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 1425 | ret = rpc_pipefs_notifier_register(&nfs4blocklayout_block); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 1426 | if (ret) |
| 1427 | goto out_remove; |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 1428 | ret = register_pernet_subsys(&nfs4blocklayout_net_ops); |
| 1429 | if (ret) |
| 1430 | goto out_notifier; |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 1431 | out: |
| 1432 | return ret; |
| 1433 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 1434 | out_notifier: |
| 1435 | rpc_pipefs_notifier_unregister(&nfs4blocklayout_block); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 1436 | out_remove: |
| 1437 | pnfs_unregister_layoutdriver(&blocklayout_type); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1438 | return ret; |
| 1439 | } |
| 1440 | |
| 1441 | static void __exit nfs4blocklayout_exit(void) |
| 1442 | { |
| 1443 | dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n", |
| 1444 | __func__); |
| 1445 | |
Stanislav Kinsbursky | 627f306 | 2012-01-10 17:04:32 +0400 | [diff] [blame] | 1446 | rpc_pipefs_notifier_unregister(&nfs4blocklayout_block); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 1447 | unregister_pernet_subsys(&nfs4blocklayout_net_ops); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1448 | pnfs_unregister_layoutdriver(&blocklayout_type); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | MODULE_ALIAS("nfs-layouttype4-3"); |
| 1452 | |
| 1453 | module_init(nfs4blocklayout_init); |
| 1454 | module_exit(nfs4blocklayout_exit); |