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