Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

zonefs: Reorganize code

Move all code related to zone file operations from super.c to the new
file.c file. Inode and zone management code remains in super.c.

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

+955 -916
+1 -1
fs/zonefs/Makefile
··· 3 3 4 4 obj-$(CONFIG_ZONEFS_FS) += zonefs.o 5 5 6 - zonefs-y := super.o sysfs.o 6 + zonefs-y := super.o file.o sysfs.o
+874
fs/zonefs/file.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Simple file system for zoned block devices exposing zones as files. 4 + * 5 + * Copyright (C) 2022 Western Digital Corporation or its affiliates. 6 + */ 7 + #include <linux/module.h> 8 + #include <linux/pagemap.h> 9 + #include <linux/iomap.h> 10 + #include <linux/init.h> 11 + #include <linux/slab.h> 12 + #include <linux/blkdev.h> 13 + #include <linux/statfs.h> 14 + #include <linux/writeback.h> 15 + #include <linux/quotaops.h> 16 + #include <linux/seq_file.h> 17 + #include <linux/parser.h> 18 + #include <linux/uio.h> 19 + #include <linux/mman.h> 20 + #include <linux/sched/mm.h> 21 + #include <linux/task_io_accounting_ops.h> 22 + 23 + #include "zonefs.h" 24 + 25 + #include "trace.h" 26 + 27 + static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, 28 + loff_t length, unsigned int flags, 29 + struct iomap *iomap, struct iomap *srcmap) 30 + { 31 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 32 + struct super_block *sb = inode->i_sb; 33 + loff_t isize; 34 + 35 + /* 36 + * All blocks are always mapped below EOF. If reading past EOF, 37 + * act as if there is a hole up to the file maximum size. 38 + */ 39 + mutex_lock(&zi->i_truncate_mutex); 40 + iomap->bdev = inode->i_sb->s_bdev; 41 + iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); 42 + isize = i_size_read(inode); 43 + if (iomap->offset >= isize) { 44 + iomap->type = IOMAP_HOLE; 45 + iomap->addr = IOMAP_NULL_ADDR; 46 + iomap->length = length; 47 + } else { 48 + iomap->type = IOMAP_MAPPED; 49 + iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; 50 + iomap->length = isize - iomap->offset; 51 + } 52 + mutex_unlock(&zi->i_truncate_mutex); 53 + 54 + trace_zonefs_iomap_begin(inode, iomap); 55 + 56 + return 0; 57 + } 58 + 59 + static const struct iomap_ops zonefs_read_iomap_ops = { 60 + .iomap_begin = zonefs_read_iomap_begin, 61 + }; 62 + 63 + static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, 64 + loff_t length, unsigned int flags, 65 + struct iomap *iomap, struct iomap *srcmap) 66 + { 67 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 68 + struct super_block *sb = inode->i_sb; 69 + loff_t isize; 70 + 71 + /* All write I/Os should always be within the file maximum size */ 72 + if (WARN_ON_ONCE(offset + length > zi->i_max_size)) 73 + return -EIO; 74 + 75 + /* 76 + * Sequential zones can only accept direct writes. This is already 77 + * checked when writes are issued, so warn if we see a page writeback 78 + * operation. 79 + */ 80 + if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ && 81 + !(flags & IOMAP_DIRECT))) 82 + return -EIO; 83 + 84 + /* 85 + * For conventional zones, all blocks are always mapped. For sequential 86 + * zones, all blocks after always mapped below the inode size (zone 87 + * write pointer) and unwriten beyond. 88 + */ 89 + mutex_lock(&zi->i_truncate_mutex); 90 + iomap->bdev = inode->i_sb->s_bdev; 91 + iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); 92 + iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; 93 + isize = i_size_read(inode); 94 + if (iomap->offset >= isize) { 95 + iomap->type = IOMAP_UNWRITTEN; 96 + iomap->length = zi->i_max_size - iomap->offset; 97 + } else { 98 + iomap->type = IOMAP_MAPPED; 99 + iomap->length = isize - iomap->offset; 100 + } 101 + mutex_unlock(&zi->i_truncate_mutex); 102 + 103 + trace_zonefs_iomap_begin(inode, iomap); 104 + 105 + return 0; 106 + } 107 + 108 + static const struct iomap_ops zonefs_write_iomap_ops = { 109 + .iomap_begin = zonefs_write_iomap_begin, 110 + }; 111 + 112 + static int zonefs_read_folio(struct file *unused, struct folio *folio) 113 + { 114 + return iomap_read_folio(folio, &zonefs_read_iomap_ops); 115 + } 116 + 117 + static void zonefs_readahead(struct readahead_control *rac) 118 + { 119 + iomap_readahead(rac, &zonefs_read_iomap_ops); 120 + } 121 + 122 + /* 123 + * Map blocks for page writeback. This is used only on conventional zone files, 124 + * which implies that the page range can only be within the fixed inode size. 125 + */ 126 + static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc, 127 + struct inode *inode, loff_t offset) 128 + { 129 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 130 + 131 + if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 132 + return -EIO; 133 + if (WARN_ON_ONCE(offset >= i_size_read(inode))) 134 + return -EIO; 135 + 136 + /* If the mapping is already OK, nothing needs to be done */ 137 + if (offset >= wpc->iomap.offset && 138 + offset < wpc->iomap.offset + wpc->iomap.length) 139 + return 0; 140 + 141 + return zonefs_write_iomap_begin(inode, offset, zi->i_max_size - offset, 142 + IOMAP_WRITE, &wpc->iomap, NULL); 143 + } 144 + 145 + static const struct iomap_writeback_ops zonefs_writeback_ops = { 146 + .map_blocks = zonefs_write_map_blocks, 147 + }; 148 + 149 + static int zonefs_writepages(struct address_space *mapping, 150 + struct writeback_control *wbc) 151 + { 152 + struct iomap_writepage_ctx wpc = { }; 153 + 154 + return iomap_writepages(mapping, wbc, &wpc, &zonefs_writeback_ops); 155 + } 156 + 157 + static int zonefs_swap_activate(struct swap_info_struct *sis, 158 + struct file *swap_file, sector_t *span) 159 + { 160 + struct inode *inode = file_inode(swap_file); 161 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 162 + 163 + if (zi->i_ztype != ZONEFS_ZTYPE_CNV) { 164 + zonefs_err(inode->i_sb, 165 + "swap file: not a conventional zone file\n"); 166 + return -EINVAL; 167 + } 168 + 169 + return iomap_swapfile_activate(sis, swap_file, span, 170 + &zonefs_read_iomap_ops); 171 + } 172 + 173 + const struct address_space_operations zonefs_file_aops = { 174 + .read_folio = zonefs_read_folio, 175 + .readahead = zonefs_readahead, 176 + .writepages = zonefs_writepages, 177 + .dirty_folio = filemap_dirty_folio, 178 + .release_folio = iomap_release_folio, 179 + .invalidate_folio = iomap_invalidate_folio, 180 + .migrate_folio = filemap_migrate_folio, 181 + .is_partially_uptodate = iomap_is_partially_uptodate, 182 + .error_remove_page = generic_error_remove_page, 183 + .direct_IO = noop_direct_IO, 184 + .swap_activate = zonefs_swap_activate, 185 + }; 186 + 187 + int zonefs_file_truncate(struct inode *inode, loff_t isize) 188 + { 189 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 190 + loff_t old_isize; 191 + enum req_op op; 192 + int ret = 0; 193 + 194 + /* 195 + * Only sequential zone files can be truncated and truncation is allowed 196 + * only down to a 0 size, which is equivalent to a zone reset, and to 197 + * the maximum file size, which is equivalent to a zone finish. 198 + */ 199 + if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 200 + return -EPERM; 201 + 202 + if (!isize) 203 + op = REQ_OP_ZONE_RESET; 204 + else if (isize == zi->i_max_size) 205 + op = REQ_OP_ZONE_FINISH; 206 + else 207 + return -EPERM; 208 + 209 + inode_dio_wait(inode); 210 + 211 + /* Serialize against page faults */ 212 + filemap_invalidate_lock(inode->i_mapping); 213 + 214 + /* Serialize against zonefs_iomap_begin() */ 215 + mutex_lock(&zi->i_truncate_mutex); 216 + 217 + old_isize = i_size_read(inode); 218 + if (isize == old_isize) 219 + goto unlock; 220 + 221 + ret = zonefs_zone_mgmt(inode, op); 222 + if (ret) 223 + goto unlock; 224 + 225 + /* 226 + * If the mount option ZONEFS_MNTOPT_EXPLICIT_OPEN is set, 227 + * take care of open zones. 228 + */ 229 + if (zi->i_flags & ZONEFS_ZONE_OPEN) { 230 + /* 231 + * Truncating a zone to EMPTY or FULL is the equivalent of 232 + * closing the zone. For a truncation to 0, we need to 233 + * re-open the zone to ensure new writes can be processed. 234 + * For a truncation to the maximum file size, the zone is 235 + * closed and writes cannot be accepted anymore, so clear 236 + * the open flag. 237 + */ 238 + if (!isize) 239 + ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_OPEN); 240 + else 241 + zi->i_flags &= ~ZONEFS_ZONE_OPEN; 242 + } 243 + 244 + zonefs_update_stats(inode, isize); 245 + truncate_setsize(inode, isize); 246 + zi->i_wpoffset = isize; 247 + zonefs_account_active(inode); 248 + 249 + unlock: 250 + mutex_unlock(&zi->i_truncate_mutex); 251 + filemap_invalidate_unlock(inode->i_mapping); 252 + 253 + return ret; 254 + } 255 + 256 + static int zonefs_file_fsync(struct file *file, loff_t start, loff_t end, 257 + int datasync) 258 + { 259 + struct inode *inode = file_inode(file); 260 + int ret = 0; 261 + 262 + if (unlikely(IS_IMMUTABLE(inode))) 263 + return -EPERM; 264 + 265 + /* 266 + * Since only direct writes are allowed in sequential files, page cache 267 + * flush is needed only for conventional zone files. 268 + */ 269 + if (ZONEFS_I(inode)->i_ztype == ZONEFS_ZTYPE_CNV) 270 + ret = file_write_and_wait_range(file, start, end); 271 + if (!ret) 272 + ret = blkdev_issue_flush(inode->i_sb->s_bdev); 273 + 274 + if (ret) 275 + zonefs_io_error(inode, true); 276 + 277 + return ret; 278 + } 279 + 280 + static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf) 281 + { 282 + struct inode *inode = file_inode(vmf->vma->vm_file); 283 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 284 + vm_fault_t ret; 285 + 286 + if (unlikely(IS_IMMUTABLE(inode))) 287 + return VM_FAULT_SIGBUS; 288 + 289 + /* 290 + * Sanity check: only conventional zone files can have shared 291 + * writeable mappings. 292 + */ 293 + if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 294 + return VM_FAULT_NOPAGE; 295 + 296 + sb_start_pagefault(inode->i_sb); 297 + file_update_time(vmf->vma->vm_file); 298 + 299 + /* Serialize against truncates */ 300 + filemap_invalidate_lock_shared(inode->i_mapping); 301 + ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops); 302 + filemap_invalidate_unlock_shared(inode->i_mapping); 303 + 304 + sb_end_pagefault(inode->i_sb); 305 + return ret; 306 + } 307 + 308 + static const struct vm_operations_struct zonefs_file_vm_ops = { 309 + .fault = filemap_fault, 310 + .map_pages = filemap_map_pages, 311 + .page_mkwrite = zonefs_filemap_page_mkwrite, 312 + }; 313 + 314 + static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma) 315 + { 316 + /* 317 + * Conventional zones accept random writes, so their files can support 318 + * shared writable mappings. For sequential zone files, only read 319 + * mappings are possible since there are no guarantees for write 320 + * ordering between msync() and page cache writeback. 321 + */ 322 + if (ZONEFS_I(file_inode(file))->i_ztype == ZONEFS_ZTYPE_SEQ && 323 + (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) 324 + return -EINVAL; 325 + 326 + file_accessed(file); 327 + vma->vm_ops = &zonefs_file_vm_ops; 328 + 329 + return 0; 330 + } 331 + 332 + static loff_t zonefs_file_llseek(struct file *file, loff_t offset, int whence) 333 + { 334 + loff_t isize = i_size_read(file_inode(file)); 335 + 336 + /* 337 + * Seeks are limited to below the zone size for conventional zones 338 + * and below the zone write pointer for sequential zones. In both 339 + * cases, this limit is the inode size. 340 + */ 341 + return generic_file_llseek_size(file, offset, whence, isize, isize); 342 + } 343 + 344 + static int zonefs_file_write_dio_end_io(struct kiocb *iocb, ssize_t size, 345 + int error, unsigned int flags) 346 + { 347 + struct inode *inode = file_inode(iocb->ki_filp); 348 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 349 + 350 + if (error) { 351 + zonefs_io_error(inode, true); 352 + return error; 353 + } 354 + 355 + if (size && zi->i_ztype != ZONEFS_ZTYPE_CNV) { 356 + /* 357 + * Note that we may be seeing completions out of order, 358 + * but that is not a problem since a write completed 359 + * successfully necessarily means that all preceding writes 360 + * were also successful. So we can safely increase the inode 361 + * size to the write end location. 362 + */ 363 + mutex_lock(&zi->i_truncate_mutex); 364 + if (i_size_read(inode) < iocb->ki_pos + size) { 365 + zonefs_update_stats(inode, iocb->ki_pos + size); 366 + zonefs_i_size_write(inode, iocb->ki_pos + size); 367 + } 368 + mutex_unlock(&zi->i_truncate_mutex); 369 + } 370 + 371 + return 0; 372 + } 373 + 374 + static const struct iomap_dio_ops zonefs_write_dio_ops = { 375 + .end_io = zonefs_file_write_dio_end_io, 376 + }; 377 + 378 + static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) 379 + { 380 + struct inode *inode = file_inode(iocb->ki_filp); 381 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 382 + struct block_device *bdev = inode->i_sb->s_bdev; 383 + unsigned int max = bdev_max_zone_append_sectors(bdev); 384 + struct bio *bio; 385 + ssize_t size; 386 + int nr_pages; 387 + ssize_t ret; 388 + 389 + max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize); 390 + iov_iter_truncate(from, max); 391 + 392 + nr_pages = iov_iter_npages(from, BIO_MAX_VECS); 393 + if (!nr_pages) 394 + return 0; 395 + 396 + bio = bio_alloc(bdev, nr_pages, 397 + REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS); 398 + bio->bi_iter.bi_sector = zi->i_zsector; 399 + bio->bi_ioprio = iocb->ki_ioprio; 400 + if (iocb_is_dsync(iocb)) 401 + bio->bi_opf |= REQ_FUA; 402 + 403 + ret = bio_iov_iter_get_pages(bio, from); 404 + if (unlikely(ret)) 405 + goto out_release; 406 + 407 + size = bio->bi_iter.bi_size; 408 + task_io_account_write(size); 409 + 410 + if (iocb->ki_flags & IOCB_HIPRI) 411 + bio_set_polled(bio, iocb); 412 + 413 + ret = submit_bio_wait(bio); 414 + 415 + /* 416 + * If the file zone was written underneath the file system, the zone 417 + * write pointer may not be where we expect it to be, but the zone 418 + * append write can still succeed. So check manually that we wrote where 419 + * we intended to, that is, at zi->i_wpoffset. 420 + */ 421 + if (!ret) { 422 + sector_t wpsector = 423 + zi->i_zsector + (zi->i_wpoffset >> SECTOR_SHIFT); 424 + 425 + if (bio->bi_iter.bi_sector != wpsector) { 426 + zonefs_warn(inode->i_sb, 427 + "Corrupted write pointer %llu for zone at %llu\n", 428 + wpsector, zi->i_zsector); 429 + ret = -EIO; 430 + } 431 + } 432 + 433 + zonefs_file_write_dio_end_io(iocb, size, ret, 0); 434 + trace_zonefs_file_dio_append(inode, size, ret); 435 + 436 + out_release: 437 + bio_release_pages(bio, false); 438 + bio_put(bio); 439 + 440 + if (ret >= 0) { 441 + iocb->ki_pos += size; 442 + return size; 443 + } 444 + 445 + return ret; 446 + } 447 + 448 + /* 449 + * Do not exceed the LFS limits nor the file zone size. If pos is under the 450 + * limit it becomes a short access. If it exceeds the limit, return -EFBIG. 451 + */ 452 + static loff_t zonefs_write_check_limits(struct file *file, loff_t pos, 453 + loff_t count) 454 + { 455 + struct inode *inode = file_inode(file); 456 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 457 + loff_t limit = rlimit(RLIMIT_FSIZE); 458 + loff_t max_size = zi->i_max_size; 459 + 460 + if (limit != RLIM_INFINITY) { 461 + if (pos >= limit) { 462 + send_sig(SIGXFSZ, current, 0); 463 + return -EFBIG; 464 + } 465 + count = min(count, limit - pos); 466 + } 467 + 468 + if (!(file->f_flags & O_LARGEFILE)) 469 + max_size = min_t(loff_t, MAX_NON_LFS, max_size); 470 + 471 + if (unlikely(pos >= max_size)) 472 + return -EFBIG; 473 + 474 + return min(count, max_size - pos); 475 + } 476 + 477 + static ssize_t zonefs_write_checks(struct kiocb *iocb, struct iov_iter *from) 478 + { 479 + struct file *file = iocb->ki_filp; 480 + struct inode *inode = file_inode(file); 481 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 482 + loff_t count; 483 + 484 + if (IS_SWAPFILE(inode)) 485 + return -ETXTBSY; 486 + 487 + if (!iov_iter_count(from)) 488 + return 0; 489 + 490 + if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) 491 + return -EINVAL; 492 + 493 + if (iocb->ki_flags & IOCB_APPEND) { 494 + if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 495 + return -EINVAL; 496 + mutex_lock(&zi->i_truncate_mutex); 497 + iocb->ki_pos = zi->i_wpoffset; 498 + mutex_unlock(&zi->i_truncate_mutex); 499 + } 500 + 501 + count = zonefs_write_check_limits(file, iocb->ki_pos, 502 + iov_iter_count(from)); 503 + if (count < 0) 504 + return count; 505 + 506 + iov_iter_truncate(from, count); 507 + return iov_iter_count(from); 508 + } 509 + 510 + /* 511 + * Handle direct writes. For sequential zone files, this is the only possible 512 + * write path. For these files, check that the user is issuing writes 513 + * sequentially from the end of the file. This code assumes that the block layer 514 + * delivers write requests to the device in sequential order. This is always the 515 + * case if a block IO scheduler implementing the ELEVATOR_F_ZBD_SEQ_WRITE 516 + * elevator feature is being used (e.g. mq-deadline). The block layer always 517 + * automatically select such an elevator for zoned block devices during the 518 + * device initialization. 519 + */ 520 + static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) 521 + { 522 + struct inode *inode = file_inode(iocb->ki_filp); 523 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 524 + struct super_block *sb = inode->i_sb; 525 + bool sync = is_sync_kiocb(iocb); 526 + bool append = false; 527 + ssize_t ret, count; 528 + 529 + /* 530 + * For async direct IOs to sequential zone files, refuse IOCB_NOWAIT 531 + * as this can cause write reordering (e.g. the first aio gets EAGAIN 532 + * on the inode lock but the second goes through but is now unaligned). 533 + */ 534 + if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !sync && 535 + (iocb->ki_flags & IOCB_NOWAIT)) 536 + return -EOPNOTSUPP; 537 + 538 + if (iocb->ki_flags & IOCB_NOWAIT) { 539 + if (!inode_trylock(inode)) 540 + return -EAGAIN; 541 + } else { 542 + inode_lock(inode); 543 + } 544 + 545 + count = zonefs_write_checks(iocb, from); 546 + if (count <= 0) { 547 + ret = count; 548 + goto inode_unlock; 549 + } 550 + 551 + if ((iocb->ki_pos | count) & (sb->s_blocksize - 1)) { 552 + ret = -EINVAL; 553 + goto inode_unlock; 554 + } 555 + 556 + /* Enforce sequential writes (append only) in sequential zones */ 557 + if (zi->i_ztype == ZONEFS_ZTYPE_SEQ) { 558 + mutex_lock(&zi->i_truncate_mutex); 559 + if (iocb->ki_pos != zi->i_wpoffset) { 560 + mutex_unlock(&zi->i_truncate_mutex); 561 + ret = -EINVAL; 562 + goto inode_unlock; 563 + } 564 + mutex_unlock(&zi->i_truncate_mutex); 565 + append = sync; 566 + } 567 + 568 + if (append) 569 + ret = zonefs_file_dio_append(iocb, from); 570 + else 571 + ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops, 572 + &zonefs_write_dio_ops, 0, NULL, 0); 573 + if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && 574 + (ret > 0 || ret == -EIOCBQUEUED)) { 575 + if (ret > 0) 576 + count = ret; 577 + 578 + /* 579 + * Update the zone write pointer offset assuming the write 580 + * operation succeeded. If it did not, the error recovery path 581 + * will correct it. Also do active seq file accounting. 582 + */ 583 + mutex_lock(&zi->i_truncate_mutex); 584 + zi->i_wpoffset += count; 585 + zonefs_account_active(inode); 586 + mutex_unlock(&zi->i_truncate_mutex); 587 + } 588 + 589 + inode_unlock: 590 + inode_unlock(inode); 591 + 592 + return ret; 593 + } 594 + 595 + static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, 596 + struct iov_iter *from) 597 + { 598 + struct inode *inode = file_inode(iocb->ki_filp); 599 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 600 + ssize_t ret; 601 + 602 + /* 603 + * Direct IO writes are mandatory for sequential zone files so that the 604 + * write IO issuing order is preserved. 605 + */ 606 + if (zi->i_ztype != ZONEFS_ZTYPE_CNV) 607 + return -EIO; 608 + 609 + if (iocb->ki_flags & IOCB_NOWAIT) { 610 + if (!inode_trylock(inode)) 611 + return -EAGAIN; 612 + } else { 613 + inode_lock(inode); 614 + } 615 + 616 + ret = zonefs_write_checks(iocb, from); 617 + if (ret <= 0) 618 + goto inode_unlock; 619 + 620 + ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops); 621 + if (ret > 0) 622 + iocb->ki_pos += ret; 623 + else if (ret == -EIO) 624 + zonefs_io_error(inode, true); 625 + 626 + inode_unlock: 627 + inode_unlock(inode); 628 + if (ret > 0) 629 + ret = generic_write_sync(iocb, ret); 630 + 631 + return ret; 632 + } 633 + 634 + static ssize_t zonefs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 635 + { 636 + struct inode *inode = file_inode(iocb->ki_filp); 637 + 638 + if (unlikely(IS_IMMUTABLE(inode))) 639 + return -EPERM; 640 + 641 + if (sb_rdonly(inode->i_sb)) 642 + return -EROFS; 643 + 644 + /* Write operations beyond the zone size are not allowed */ 645 + if (iocb->ki_pos >= ZONEFS_I(inode)->i_max_size) 646 + return -EFBIG; 647 + 648 + if (iocb->ki_flags & IOCB_DIRECT) { 649 + ssize_t ret = zonefs_file_dio_write(iocb, from); 650 + 651 + if (ret != -ENOTBLK) 652 + return ret; 653 + } 654 + 655 + return zonefs_file_buffered_write(iocb, from); 656 + } 657 + 658 + static int zonefs_file_read_dio_end_io(struct kiocb *iocb, ssize_t size, 659 + int error, unsigned int flags) 660 + { 661 + if (error) { 662 + zonefs_io_error(file_inode(iocb->ki_filp), false); 663 + return error; 664 + } 665 + 666 + return 0; 667 + } 668 + 669 + static const struct iomap_dio_ops zonefs_read_dio_ops = { 670 + .end_io = zonefs_file_read_dio_end_io, 671 + }; 672 + 673 + static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) 674 + { 675 + struct inode *inode = file_inode(iocb->ki_filp); 676 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 677 + struct super_block *sb = inode->i_sb; 678 + loff_t isize; 679 + ssize_t ret; 680 + 681 + /* Offline zones cannot be read */ 682 + if (unlikely(IS_IMMUTABLE(inode) && !(inode->i_mode & 0777))) 683 + return -EPERM; 684 + 685 + if (iocb->ki_pos >= zi->i_max_size) 686 + return 0; 687 + 688 + if (iocb->ki_flags & IOCB_NOWAIT) { 689 + if (!inode_trylock_shared(inode)) 690 + return -EAGAIN; 691 + } else { 692 + inode_lock_shared(inode); 693 + } 694 + 695 + /* Limit read operations to written data */ 696 + mutex_lock(&zi->i_truncate_mutex); 697 + isize = i_size_read(inode); 698 + if (iocb->ki_pos >= isize) { 699 + mutex_unlock(&zi->i_truncate_mutex); 700 + ret = 0; 701 + goto inode_unlock; 702 + } 703 + iov_iter_truncate(to, isize - iocb->ki_pos); 704 + mutex_unlock(&zi->i_truncate_mutex); 705 + 706 + if (iocb->ki_flags & IOCB_DIRECT) { 707 + size_t count = iov_iter_count(to); 708 + 709 + if ((iocb->ki_pos | count) & (sb->s_blocksize - 1)) { 710 + ret = -EINVAL; 711 + goto inode_unlock; 712 + } 713 + file_accessed(iocb->ki_filp); 714 + ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops, 715 + &zonefs_read_dio_ops, 0, NULL, 0); 716 + } else { 717 + ret = generic_file_read_iter(iocb, to); 718 + if (ret == -EIO) 719 + zonefs_io_error(inode, false); 720 + } 721 + 722 + inode_unlock: 723 + inode_unlock_shared(inode); 724 + 725 + return ret; 726 + } 727 + 728 + /* 729 + * Write open accounting is done only for sequential files. 730 + */ 731 + static inline bool zonefs_seq_file_need_wro(struct inode *inode, 732 + struct file *file) 733 + { 734 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 735 + 736 + if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 737 + return false; 738 + 739 + if (!(file->f_mode & FMODE_WRITE)) 740 + return false; 741 + 742 + return true; 743 + } 744 + 745 + static int zonefs_seq_file_write_open(struct inode *inode) 746 + { 747 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 748 + int ret = 0; 749 + 750 + mutex_lock(&zi->i_truncate_mutex); 751 + 752 + if (!zi->i_wr_refcnt) { 753 + struct zonefs_sb_info *sbi = ZONEFS_SB(inode->i_sb); 754 + unsigned int wro = atomic_inc_return(&sbi->s_wro_seq_files); 755 + 756 + if (sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { 757 + 758 + if (sbi->s_max_wro_seq_files 759 + && wro > sbi->s_max_wro_seq_files) { 760 + atomic_dec(&sbi->s_wro_seq_files); 761 + ret = -EBUSY; 762 + goto unlock; 763 + } 764 + 765 + if (i_size_read(inode) < zi->i_max_size) { 766 + ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_OPEN); 767 + if (ret) { 768 + atomic_dec(&sbi->s_wro_seq_files); 769 + goto unlock; 770 + } 771 + zi->i_flags |= ZONEFS_ZONE_OPEN; 772 + zonefs_account_active(inode); 773 + } 774 + } 775 + } 776 + 777 + zi->i_wr_refcnt++; 778 + 779 + unlock: 780 + mutex_unlock(&zi->i_truncate_mutex); 781 + 782 + return ret; 783 + } 784 + 785 + static int zonefs_file_open(struct inode *inode, struct file *file) 786 + { 787 + int ret; 788 + 789 + ret = generic_file_open(inode, file); 790 + if (ret) 791 + return ret; 792 + 793 + if (zonefs_seq_file_need_wro(inode, file)) 794 + return zonefs_seq_file_write_open(inode); 795 + 796 + return 0; 797 + } 798 + 799 + static void zonefs_seq_file_write_close(struct inode *inode) 800 + { 801 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 802 + struct super_block *sb = inode->i_sb; 803 + struct zonefs_sb_info *sbi = ZONEFS_SB(sb); 804 + int ret = 0; 805 + 806 + mutex_lock(&zi->i_truncate_mutex); 807 + 808 + zi->i_wr_refcnt--; 809 + if (zi->i_wr_refcnt) 810 + goto unlock; 811 + 812 + /* 813 + * The file zone may not be open anymore (e.g. the file was truncated to 814 + * its maximum size or it was fully written). For this case, we only 815 + * need to decrement the write open count. 816 + */ 817 + if (zi->i_flags & ZONEFS_ZONE_OPEN) { 818 + ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_CLOSE); 819 + if (ret) { 820 + __zonefs_io_error(inode, false); 821 + /* 822 + * Leaving zones explicitly open may lead to a state 823 + * where most zones cannot be written (zone resources 824 + * exhausted). So take preventive action by remounting 825 + * read-only. 826 + */ 827 + if (zi->i_flags & ZONEFS_ZONE_OPEN && 828 + !(sb->s_flags & SB_RDONLY)) { 829 + zonefs_warn(sb, 830 + "closing zone at %llu failed %d\n", 831 + zi->i_zsector, ret); 832 + zonefs_warn(sb, 833 + "remounting filesystem read-only\n"); 834 + sb->s_flags |= SB_RDONLY; 835 + } 836 + goto unlock; 837 + } 838 + 839 + zi->i_flags &= ~ZONEFS_ZONE_OPEN; 840 + zonefs_account_active(inode); 841 + } 842 + 843 + atomic_dec(&sbi->s_wro_seq_files); 844 + 845 + unlock: 846 + mutex_unlock(&zi->i_truncate_mutex); 847 + } 848 + 849 + static int zonefs_file_release(struct inode *inode, struct file *file) 850 + { 851 + /* 852 + * If we explicitly open a zone we must close it again as well, but the 853 + * zone management operation can fail (either due to an IO error or as 854 + * the zone has gone offline or read-only). Make sure we don't fail the 855 + * close(2) for user-space. 856 + */ 857 + if (zonefs_seq_file_need_wro(inode, file)) 858 + zonefs_seq_file_write_close(inode); 859 + 860 + return 0; 861 + } 862 + 863 + const struct file_operations zonefs_file_operations = { 864 + .open = zonefs_file_open, 865 + .release = zonefs_file_release, 866 + .fsync = zonefs_file_fsync, 867 + .mmap = zonefs_file_mmap, 868 + .llseek = zonefs_file_llseek, 869 + .read_iter = zonefs_file_read_iter, 870 + .write_iter = zonefs_file_write_iter, 871 + .splice_read = generic_file_splice_read, 872 + .splice_write = iter_file_splice_write, 873 + .iopoll = iocb_bio_iopoll, 874 + };
+58 -915
fs/zonefs/super.c
··· 30 30 /* 31 31 * Manage the active zone count. Called with zi->i_truncate_mutex held. 32 32 */ 33 - static void zonefs_account_active(struct inode *inode) 33 + void zonefs_account_active(struct inode *inode) 34 34 { 35 35 struct zonefs_sb_info *sbi = ZONEFS_SB(inode->i_sb); 36 36 struct zonefs_inode_info *zi = ZONEFS_I(inode); ··· 68 68 } 69 69 } 70 70 71 - static inline int zonefs_zone_mgmt(struct inode *inode, enum req_op op) 71 + int zonefs_zone_mgmt(struct inode *inode, enum req_op op) 72 72 { 73 73 struct zonefs_inode_info *zi = ZONEFS_I(inode); 74 74 int ret; ··· 99 99 return 0; 100 100 } 101 101 102 - static inline void zonefs_i_size_write(struct inode *inode, loff_t isize) 102 + void zonefs_i_size_write(struct inode *inode, loff_t isize) 103 103 { 104 104 struct zonefs_inode_info *zi = ZONEFS_I(inode); 105 105 ··· 117 117 } 118 118 } 119 119 120 - static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, 121 - loff_t length, unsigned int flags, 122 - struct iomap *iomap, struct iomap *srcmap) 123 - { 124 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 125 - struct super_block *sb = inode->i_sb; 126 - loff_t isize; 127 - 128 - /* 129 - * All blocks are always mapped below EOF. If reading past EOF, 130 - * act as if there is a hole up to the file maximum size. 131 - */ 132 - mutex_lock(&zi->i_truncate_mutex); 133 - iomap->bdev = inode->i_sb->s_bdev; 134 - iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); 135 - isize = i_size_read(inode); 136 - if (iomap->offset >= isize) { 137 - iomap->type = IOMAP_HOLE; 138 - iomap->addr = IOMAP_NULL_ADDR; 139 - iomap->length = length; 140 - } else { 141 - iomap->type = IOMAP_MAPPED; 142 - iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; 143 - iomap->length = isize - iomap->offset; 144 - } 145 - mutex_unlock(&zi->i_truncate_mutex); 146 - 147 - trace_zonefs_iomap_begin(inode, iomap); 148 - 149 - return 0; 150 - } 151 - 152 - static const struct iomap_ops zonefs_read_iomap_ops = { 153 - .iomap_begin = zonefs_read_iomap_begin, 154 - }; 155 - 156 - static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, 157 - loff_t length, unsigned int flags, 158 - struct iomap *iomap, struct iomap *srcmap) 159 - { 160 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 161 - struct super_block *sb = inode->i_sb; 162 - loff_t isize; 163 - 164 - /* All write I/Os should always be within the file maximum size */ 165 - if (WARN_ON_ONCE(offset + length > zi->i_max_size)) 166 - return -EIO; 167 - 168 - /* 169 - * Sequential zones can only accept direct writes. This is already 170 - * checked when writes are issued, so warn if we see a page writeback 171 - * operation. 172 - */ 173 - if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ && 174 - !(flags & IOMAP_DIRECT))) 175 - return -EIO; 176 - 177 - /* 178 - * For conventional zones, all blocks are always mapped. For sequential 179 - * zones, all blocks after always mapped below the inode size (zone 180 - * write pointer) and unwriten beyond. 181 - */ 182 - mutex_lock(&zi->i_truncate_mutex); 183 - iomap->bdev = inode->i_sb->s_bdev; 184 - iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); 185 - iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; 186 - isize = i_size_read(inode); 187 - if (iomap->offset >= isize) { 188 - iomap->type = IOMAP_UNWRITTEN; 189 - iomap->length = zi->i_max_size - iomap->offset; 190 - } else { 191 - iomap->type = IOMAP_MAPPED; 192 - iomap->length = isize - iomap->offset; 193 - } 194 - mutex_unlock(&zi->i_truncate_mutex); 195 - 196 - trace_zonefs_iomap_begin(inode, iomap); 197 - 198 - return 0; 199 - } 200 - 201 - static const struct iomap_ops zonefs_write_iomap_ops = { 202 - .iomap_begin = zonefs_write_iomap_begin, 203 - }; 204 - 205 - static int zonefs_read_folio(struct file *unused, struct folio *folio) 206 - { 207 - return iomap_read_folio(folio, &zonefs_read_iomap_ops); 208 - } 209 - 210 - static void zonefs_readahead(struct readahead_control *rac) 211 - { 212 - iomap_readahead(rac, &zonefs_read_iomap_ops); 213 - } 214 - 215 - /* 216 - * Map blocks for page writeback. This is used only on conventional zone files, 217 - * which implies that the page range can only be within the fixed inode size. 218 - */ 219 - static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc, 220 - struct inode *inode, loff_t offset) 221 - { 222 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 223 - 224 - if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 225 - return -EIO; 226 - if (WARN_ON_ONCE(offset >= i_size_read(inode))) 227 - return -EIO; 228 - 229 - /* If the mapping is already OK, nothing needs to be done */ 230 - if (offset >= wpc->iomap.offset && 231 - offset < wpc->iomap.offset + wpc->iomap.length) 232 - return 0; 233 - 234 - return zonefs_write_iomap_begin(inode, offset, zi->i_max_size - offset, 235 - IOMAP_WRITE, &wpc->iomap, NULL); 236 - } 237 - 238 - static const struct iomap_writeback_ops zonefs_writeback_ops = { 239 - .map_blocks = zonefs_write_map_blocks, 240 - }; 241 - 242 - static int zonefs_writepages(struct address_space *mapping, 243 - struct writeback_control *wbc) 244 - { 245 - struct iomap_writepage_ctx wpc = { }; 246 - 247 - return iomap_writepages(mapping, wbc, &wpc, &zonefs_writeback_ops); 248 - } 249 - 250 - static int zonefs_swap_activate(struct swap_info_struct *sis, 251 - struct file *swap_file, sector_t *span) 252 - { 253 - struct inode *inode = file_inode(swap_file); 254 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 255 - 256 - if (zi->i_ztype != ZONEFS_ZTYPE_CNV) { 257 - zonefs_err(inode->i_sb, 258 - "swap file: not a conventional zone file\n"); 259 - return -EINVAL; 260 - } 261 - 262 - return iomap_swapfile_activate(sis, swap_file, span, 263 - &zonefs_read_iomap_ops); 264 - } 265 - 266 - static const struct address_space_operations zonefs_file_aops = { 267 - .read_folio = zonefs_read_folio, 268 - .readahead = zonefs_readahead, 269 - .writepages = zonefs_writepages, 270 - .dirty_folio = filemap_dirty_folio, 271 - .release_folio = iomap_release_folio, 272 - .invalidate_folio = iomap_invalidate_folio, 273 - .migrate_folio = filemap_migrate_folio, 274 - .is_partially_uptodate = iomap_is_partially_uptodate, 275 - .error_remove_page = generic_error_remove_page, 276 - .direct_IO = noop_direct_IO, 277 - .swap_activate = zonefs_swap_activate, 278 - }; 279 - 280 - static void zonefs_update_stats(struct inode *inode, loff_t new_isize) 120 + void zonefs_update_stats(struct inode *inode, loff_t new_isize) 281 121 { 282 122 struct super_block *sb = inode->i_sb; 283 123 struct zonefs_sb_info *sbi = ZONEFS_SB(sb); ··· 327 487 * eventually correct the file size and zonefs inode write pointer offset 328 488 * (which can be out of sync with the drive due to partial write failures). 329 489 */ 330 - static void __zonefs_io_error(struct inode *inode, bool write) 490 + void __zonefs_io_error(struct inode *inode, bool write) 331 491 { 332 492 struct zonefs_inode_info *zi = ZONEFS_I(inode); 333 493 struct super_block *sb = inode->i_sb; ··· 365 525 inode->i_ino, ret); 366 526 memalloc_noio_restore(noio_flag); 367 527 } 368 - 369 - static void zonefs_io_error(struct inode *inode, bool write) 370 - { 371 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 372 - 373 - mutex_lock(&zi->i_truncate_mutex); 374 - __zonefs_io_error(inode, write); 375 - mutex_unlock(&zi->i_truncate_mutex); 376 - } 377 - 378 - static int zonefs_file_truncate(struct inode *inode, loff_t isize) 379 - { 380 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 381 - loff_t old_isize; 382 - enum req_op op; 383 - int ret = 0; 384 - 385 - /* 386 - * Only sequential zone files can be truncated and truncation is allowed 387 - * only down to a 0 size, which is equivalent to a zone reset, and to 388 - * the maximum file size, which is equivalent to a zone finish. 389 - */ 390 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 391 - return -EPERM; 392 - 393 - if (!isize) 394 - op = REQ_OP_ZONE_RESET; 395 - else if (isize == zi->i_max_size) 396 - op = REQ_OP_ZONE_FINISH; 397 - else 398 - return -EPERM; 399 - 400 - inode_dio_wait(inode); 401 - 402 - /* Serialize against page faults */ 403 - filemap_invalidate_lock(inode->i_mapping); 404 - 405 - /* Serialize against zonefs_iomap_begin() */ 406 - mutex_lock(&zi->i_truncate_mutex); 407 - 408 - old_isize = i_size_read(inode); 409 - if (isize == old_isize) 410 - goto unlock; 411 - 412 - ret = zonefs_zone_mgmt(inode, op); 413 - if (ret) 414 - goto unlock; 415 - 416 - /* 417 - * If the mount option ZONEFS_MNTOPT_EXPLICIT_OPEN is set, 418 - * take care of open zones. 419 - */ 420 - if (zi->i_flags & ZONEFS_ZONE_OPEN) { 421 - /* 422 - * Truncating a zone to EMPTY or FULL is the equivalent of 423 - * closing the zone. For a truncation to 0, we need to 424 - * re-open the zone to ensure new writes can be processed. 425 - * For a truncation to the maximum file size, the zone is 426 - * closed and writes cannot be accepted anymore, so clear 427 - * the open flag. 428 - */ 429 - if (!isize) 430 - ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_OPEN); 431 - else 432 - zi->i_flags &= ~ZONEFS_ZONE_OPEN; 433 - } 434 - 435 - zonefs_update_stats(inode, isize); 436 - truncate_setsize(inode, isize); 437 - zi->i_wpoffset = isize; 438 - zonefs_account_active(inode); 439 - 440 - unlock: 441 - mutex_unlock(&zi->i_truncate_mutex); 442 - filemap_invalidate_unlock(inode->i_mapping); 443 - 444 - return ret; 445 - } 446 - 447 - static int zonefs_inode_setattr(struct user_namespace *mnt_userns, 448 - struct dentry *dentry, struct iattr *iattr) 449 - { 450 - struct inode *inode = d_inode(dentry); 451 - int ret; 452 - 453 - if (unlikely(IS_IMMUTABLE(inode))) 454 - return -EPERM; 455 - 456 - ret = setattr_prepare(&init_user_ns, dentry, iattr); 457 - if (ret) 458 - return ret; 459 - 460 - /* 461 - * Since files and directories cannot be created nor deleted, do not 462 - * allow setting any write attributes on the sub-directories grouping 463 - * files by zone type. 464 - */ 465 - if ((iattr->ia_valid & ATTR_MODE) && S_ISDIR(inode->i_mode) && 466 - (iattr->ia_mode & 0222)) 467 - return -EPERM; 468 - 469 - if (((iattr->ia_valid & ATTR_UID) && 470 - !uid_eq(iattr->ia_uid, inode->i_uid)) || 471 - ((iattr->ia_valid & ATTR_GID) && 472 - !gid_eq(iattr->ia_gid, inode->i_gid))) { 473 - ret = dquot_transfer(mnt_userns, inode, iattr); 474 - if (ret) 475 - return ret; 476 - } 477 - 478 - if (iattr->ia_valid & ATTR_SIZE) { 479 - ret = zonefs_file_truncate(inode, iattr->ia_size); 480 - if (ret) 481 - return ret; 482 - } 483 - 484 - setattr_copy(&init_user_ns, inode, iattr); 485 - 486 - return 0; 487 - } 488 - 489 - static const struct inode_operations zonefs_file_inode_operations = { 490 - .setattr = zonefs_inode_setattr, 491 - }; 492 - 493 - static int zonefs_file_fsync(struct file *file, loff_t start, loff_t end, 494 - int datasync) 495 - { 496 - struct inode *inode = file_inode(file); 497 - int ret = 0; 498 - 499 - if (unlikely(IS_IMMUTABLE(inode))) 500 - return -EPERM; 501 - 502 - /* 503 - * Since only direct writes are allowed in sequential files, page cache 504 - * flush is needed only for conventional zone files. 505 - */ 506 - if (ZONEFS_I(inode)->i_ztype == ZONEFS_ZTYPE_CNV) 507 - ret = file_write_and_wait_range(file, start, end); 508 - if (!ret) 509 - ret = blkdev_issue_flush(inode->i_sb->s_bdev); 510 - 511 - if (ret) 512 - zonefs_io_error(inode, true); 513 - 514 - return ret; 515 - } 516 - 517 - static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf) 518 - { 519 - struct inode *inode = file_inode(vmf->vma->vm_file); 520 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 521 - vm_fault_t ret; 522 - 523 - if (unlikely(IS_IMMUTABLE(inode))) 524 - return VM_FAULT_SIGBUS; 525 - 526 - /* 527 - * Sanity check: only conventional zone files can have shared 528 - * writeable mappings. 529 - */ 530 - if (WARN_ON_ONCE(zi->i_ztype != ZONEFS_ZTYPE_CNV)) 531 - return VM_FAULT_NOPAGE; 532 - 533 - sb_start_pagefault(inode->i_sb); 534 - file_update_time(vmf->vma->vm_file); 535 - 536 - /* Serialize against truncates */ 537 - filemap_invalidate_lock_shared(inode->i_mapping); 538 - ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops); 539 - filemap_invalidate_unlock_shared(inode->i_mapping); 540 - 541 - sb_end_pagefault(inode->i_sb); 542 - return ret; 543 - } 544 - 545 - static const struct vm_operations_struct zonefs_file_vm_ops = { 546 - .fault = filemap_fault, 547 - .map_pages = filemap_map_pages, 548 - .page_mkwrite = zonefs_filemap_page_mkwrite, 549 - }; 550 - 551 - static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma) 552 - { 553 - /* 554 - * Conventional zones accept random writes, so their files can support 555 - * shared writable mappings. For sequential zone files, only read 556 - * mappings are possible since there are no guarantees for write 557 - * ordering between msync() and page cache writeback. 558 - */ 559 - if (ZONEFS_I(file_inode(file))->i_ztype == ZONEFS_ZTYPE_SEQ && 560 - (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) 561 - return -EINVAL; 562 - 563 - file_accessed(file); 564 - vma->vm_ops = &zonefs_file_vm_ops; 565 - 566 - return 0; 567 - } 568 - 569 - static loff_t zonefs_file_llseek(struct file *file, loff_t offset, int whence) 570 - { 571 - loff_t isize = i_size_read(file_inode(file)); 572 - 573 - /* 574 - * Seeks are limited to below the zone size for conventional zones 575 - * and below the zone write pointer for sequential zones. In both 576 - * cases, this limit is the inode size. 577 - */ 578 - return generic_file_llseek_size(file, offset, whence, isize, isize); 579 - } 580 - 581 - static int zonefs_file_write_dio_end_io(struct kiocb *iocb, ssize_t size, 582 - int error, unsigned int flags) 583 - { 584 - struct inode *inode = file_inode(iocb->ki_filp); 585 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 586 - 587 - if (error) { 588 - zonefs_io_error(inode, true); 589 - return error; 590 - } 591 - 592 - if (size && zi->i_ztype != ZONEFS_ZTYPE_CNV) { 593 - /* 594 - * Note that we may be seeing completions out of order, 595 - * but that is not a problem since a write completed 596 - * successfully necessarily means that all preceding writes 597 - * were also successful. So we can safely increase the inode 598 - * size to the write end location. 599 - */ 600 - mutex_lock(&zi->i_truncate_mutex); 601 - if (i_size_read(inode) < iocb->ki_pos + size) { 602 - zonefs_update_stats(inode, iocb->ki_pos + size); 603 - zonefs_i_size_write(inode, iocb->ki_pos + size); 604 - } 605 - mutex_unlock(&zi->i_truncate_mutex); 606 - } 607 - 608 - return 0; 609 - } 610 - 611 - static const struct iomap_dio_ops zonefs_write_dio_ops = { 612 - .end_io = zonefs_file_write_dio_end_io, 613 - }; 614 - 615 - static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) 616 - { 617 - struct inode *inode = file_inode(iocb->ki_filp); 618 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 619 - struct block_device *bdev = inode->i_sb->s_bdev; 620 - unsigned int max = bdev_max_zone_append_sectors(bdev); 621 - struct bio *bio; 622 - ssize_t size; 623 - int nr_pages; 624 - ssize_t ret; 625 - 626 - max = ALIGN_DOWN(max << SECTOR_SHIFT, inode->i_sb->s_blocksize); 627 - iov_iter_truncate(from, max); 628 - 629 - nr_pages = iov_iter_npages(from, BIO_MAX_VECS); 630 - if (!nr_pages) 631 - return 0; 632 - 633 - bio = bio_alloc(bdev, nr_pages, 634 - REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE, GFP_NOFS); 635 - bio->bi_iter.bi_sector = zi->i_zsector; 636 - bio->bi_ioprio = iocb->ki_ioprio; 637 - if (iocb_is_dsync(iocb)) 638 - bio->bi_opf |= REQ_FUA; 639 - 640 - ret = bio_iov_iter_get_pages(bio, from); 641 - if (unlikely(ret)) 642 - goto out_release; 643 - 644 - size = bio->bi_iter.bi_size; 645 - task_io_account_write(size); 646 - 647 - if (iocb->ki_flags & IOCB_HIPRI) 648 - bio_set_polled(bio, iocb); 649 - 650 - ret = submit_bio_wait(bio); 651 - 652 - /* 653 - * If the file zone was written underneath the file system, the zone 654 - * write pointer may not be where we expect it to be, but the zone 655 - * append write can still succeed. So check manually that we wrote where 656 - * we intended to, that is, at zi->i_wpoffset. 657 - */ 658 - if (!ret) { 659 - sector_t wpsector = 660 - zi->i_zsector + (zi->i_wpoffset >> SECTOR_SHIFT); 661 - 662 - if (bio->bi_iter.bi_sector != wpsector) { 663 - zonefs_warn(inode->i_sb, 664 - "Corrupted write pointer %llu for zone at %llu\n", 665 - wpsector, zi->i_zsector); 666 - ret = -EIO; 667 - } 668 - } 669 - 670 - zonefs_file_write_dio_end_io(iocb, size, ret, 0); 671 - trace_zonefs_file_dio_append(inode, size, ret); 672 - 673 - out_release: 674 - bio_release_pages(bio, false); 675 - bio_put(bio); 676 - 677 - if (ret >= 0) { 678 - iocb->ki_pos += size; 679 - return size; 680 - } 681 - 682 - return ret; 683 - } 684 - 685 - /* 686 - * Do not exceed the LFS limits nor the file zone size. If pos is under the 687 - * limit it becomes a short access. If it exceeds the limit, return -EFBIG. 688 - */ 689 - static loff_t zonefs_write_check_limits(struct file *file, loff_t pos, 690 - loff_t count) 691 - { 692 - struct inode *inode = file_inode(file); 693 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 694 - loff_t limit = rlimit(RLIMIT_FSIZE); 695 - loff_t max_size = zi->i_max_size; 696 - 697 - if (limit != RLIM_INFINITY) { 698 - if (pos >= limit) { 699 - send_sig(SIGXFSZ, current, 0); 700 - return -EFBIG; 701 - } 702 - count = min(count, limit - pos); 703 - } 704 - 705 - if (!(file->f_flags & O_LARGEFILE)) 706 - max_size = min_t(loff_t, MAX_NON_LFS, max_size); 707 - 708 - if (unlikely(pos >= max_size)) 709 - return -EFBIG; 710 - 711 - return min(count, max_size - pos); 712 - } 713 - 714 - static ssize_t zonefs_write_checks(struct kiocb *iocb, struct iov_iter *from) 715 - { 716 - struct file *file = iocb->ki_filp; 717 - struct inode *inode = file_inode(file); 718 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 719 - loff_t count; 720 - 721 - if (IS_SWAPFILE(inode)) 722 - return -ETXTBSY; 723 - 724 - if (!iov_iter_count(from)) 725 - return 0; 726 - 727 - if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT)) 728 - return -EINVAL; 729 - 730 - if (iocb->ki_flags & IOCB_APPEND) { 731 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 732 - return -EINVAL; 733 - mutex_lock(&zi->i_truncate_mutex); 734 - iocb->ki_pos = zi->i_wpoffset; 735 - mutex_unlock(&zi->i_truncate_mutex); 736 - } 737 - 738 - count = zonefs_write_check_limits(file, iocb->ki_pos, 739 - iov_iter_count(from)); 740 - if (count < 0) 741 - return count; 742 - 743 - iov_iter_truncate(from, count); 744 - return iov_iter_count(from); 745 - } 746 - 747 - /* 748 - * Handle direct writes. For sequential zone files, this is the only possible 749 - * write path. For these files, check that the user is issuing writes 750 - * sequentially from the end of the file. This code assumes that the block layer 751 - * delivers write requests to the device in sequential order. This is always the 752 - * case if a block IO scheduler implementing the ELEVATOR_F_ZBD_SEQ_WRITE 753 - * elevator feature is being used (e.g. mq-deadline). The block layer always 754 - * automatically select such an elevator for zoned block devices during the 755 - * device initialization. 756 - */ 757 - static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from) 758 - { 759 - struct inode *inode = file_inode(iocb->ki_filp); 760 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 761 - struct super_block *sb = inode->i_sb; 762 - bool sync = is_sync_kiocb(iocb); 763 - bool append = false; 764 - ssize_t ret, count; 765 - 766 - /* 767 - * For async direct IOs to sequential zone files, refuse IOCB_NOWAIT 768 - * as this can cause write reordering (e.g. the first aio gets EAGAIN 769 - * on the inode lock but the second goes through but is now unaligned). 770 - */ 771 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && !sync && 772 - (iocb->ki_flags & IOCB_NOWAIT)) 773 - return -EOPNOTSUPP; 774 - 775 - if (iocb->ki_flags & IOCB_NOWAIT) { 776 - if (!inode_trylock(inode)) 777 - return -EAGAIN; 778 - } else { 779 - inode_lock(inode); 780 - } 781 - 782 - count = zonefs_write_checks(iocb, from); 783 - if (count <= 0) { 784 - ret = count; 785 - goto inode_unlock; 786 - } 787 - 788 - if ((iocb->ki_pos | count) & (sb->s_blocksize - 1)) { 789 - ret = -EINVAL; 790 - goto inode_unlock; 791 - } 792 - 793 - /* Enforce sequential writes (append only) in sequential zones */ 794 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ) { 795 - mutex_lock(&zi->i_truncate_mutex); 796 - if (iocb->ki_pos != zi->i_wpoffset) { 797 - mutex_unlock(&zi->i_truncate_mutex); 798 - ret = -EINVAL; 799 - goto inode_unlock; 800 - } 801 - mutex_unlock(&zi->i_truncate_mutex); 802 - append = sync; 803 - } 804 - 805 - if (append) 806 - ret = zonefs_file_dio_append(iocb, from); 807 - else 808 - ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops, 809 - &zonefs_write_dio_ops, 0, NULL, 0); 810 - if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && 811 - (ret > 0 || ret == -EIOCBQUEUED)) { 812 - if (ret > 0) 813 - count = ret; 814 - 815 - /* 816 - * Update the zone write pointer offset assuming the write 817 - * operation succeeded. If it did not, the error recovery path 818 - * will correct it. Also do active seq file accounting. 819 - */ 820 - mutex_lock(&zi->i_truncate_mutex); 821 - zi->i_wpoffset += count; 822 - zonefs_account_active(inode); 823 - mutex_unlock(&zi->i_truncate_mutex); 824 - } 825 - 826 - inode_unlock: 827 - inode_unlock(inode); 828 - 829 - return ret; 830 - } 831 - 832 - static ssize_t zonefs_file_buffered_write(struct kiocb *iocb, 833 - struct iov_iter *from) 834 - { 835 - struct inode *inode = file_inode(iocb->ki_filp); 836 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 837 - ssize_t ret; 838 - 839 - /* 840 - * Direct IO writes are mandatory for sequential zone files so that the 841 - * write IO issuing order is preserved. 842 - */ 843 - if (zi->i_ztype != ZONEFS_ZTYPE_CNV) 844 - return -EIO; 845 - 846 - if (iocb->ki_flags & IOCB_NOWAIT) { 847 - if (!inode_trylock(inode)) 848 - return -EAGAIN; 849 - } else { 850 - inode_lock(inode); 851 - } 852 - 853 - ret = zonefs_write_checks(iocb, from); 854 - if (ret <= 0) 855 - goto inode_unlock; 856 - 857 - ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops); 858 - if (ret > 0) 859 - iocb->ki_pos += ret; 860 - else if (ret == -EIO) 861 - zonefs_io_error(inode, true); 862 - 863 - inode_unlock: 864 - inode_unlock(inode); 865 - if (ret > 0) 866 - ret = generic_write_sync(iocb, ret); 867 - 868 - return ret; 869 - } 870 - 871 - static ssize_t zonefs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) 872 - { 873 - struct inode *inode = file_inode(iocb->ki_filp); 874 - 875 - if (unlikely(IS_IMMUTABLE(inode))) 876 - return -EPERM; 877 - 878 - if (sb_rdonly(inode->i_sb)) 879 - return -EROFS; 880 - 881 - /* Write operations beyond the zone size are not allowed */ 882 - if (iocb->ki_pos >= ZONEFS_I(inode)->i_max_size) 883 - return -EFBIG; 884 - 885 - if (iocb->ki_flags & IOCB_DIRECT) { 886 - ssize_t ret = zonefs_file_dio_write(iocb, from); 887 - if (ret != -ENOTBLK) 888 - return ret; 889 - } 890 - 891 - return zonefs_file_buffered_write(iocb, from); 892 - } 893 - 894 - static int zonefs_file_read_dio_end_io(struct kiocb *iocb, ssize_t size, 895 - int error, unsigned int flags) 896 - { 897 - if (error) { 898 - zonefs_io_error(file_inode(iocb->ki_filp), false); 899 - return error; 900 - } 901 - 902 - return 0; 903 - } 904 - 905 - static const struct iomap_dio_ops zonefs_read_dio_ops = { 906 - .end_io = zonefs_file_read_dio_end_io, 907 - }; 908 - 909 - static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) 910 - { 911 - struct inode *inode = file_inode(iocb->ki_filp); 912 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 913 - struct super_block *sb = inode->i_sb; 914 - loff_t isize; 915 - ssize_t ret; 916 - 917 - /* Offline zones cannot be read */ 918 - if (unlikely(IS_IMMUTABLE(inode) && !(inode->i_mode & 0777))) 919 - return -EPERM; 920 - 921 - if (iocb->ki_pos >= zi->i_max_size) 922 - return 0; 923 - 924 - if (iocb->ki_flags & IOCB_NOWAIT) { 925 - if (!inode_trylock_shared(inode)) 926 - return -EAGAIN; 927 - } else { 928 - inode_lock_shared(inode); 929 - } 930 - 931 - /* Limit read operations to written data */ 932 - mutex_lock(&zi->i_truncate_mutex); 933 - isize = i_size_read(inode); 934 - if (iocb->ki_pos >= isize) { 935 - mutex_unlock(&zi->i_truncate_mutex); 936 - ret = 0; 937 - goto inode_unlock; 938 - } 939 - iov_iter_truncate(to, isize - iocb->ki_pos); 940 - mutex_unlock(&zi->i_truncate_mutex); 941 - 942 - if (iocb->ki_flags & IOCB_DIRECT) { 943 - size_t count = iov_iter_count(to); 944 - 945 - if ((iocb->ki_pos | count) & (sb->s_blocksize - 1)) { 946 - ret = -EINVAL; 947 - goto inode_unlock; 948 - } 949 - file_accessed(iocb->ki_filp); 950 - ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops, 951 - &zonefs_read_dio_ops, 0, NULL, 0); 952 - } else { 953 - ret = generic_file_read_iter(iocb, to); 954 - if (ret == -EIO) 955 - zonefs_io_error(inode, false); 956 - } 957 - 958 - inode_unlock: 959 - inode_unlock_shared(inode); 960 - 961 - return ret; 962 - } 963 - 964 - /* 965 - * Write open accounting is done only for sequential files. 966 - */ 967 - static inline bool zonefs_seq_file_need_wro(struct inode *inode, 968 - struct file *file) 969 - { 970 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 971 - 972 - if (zi->i_ztype != ZONEFS_ZTYPE_SEQ) 973 - return false; 974 - 975 - if (!(file->f_mode & FMODE_WRITE)) 976 - return false; 977 - 978 - return true; 979 - } 980 - 981 - static int zonefs_seq_file_write_open(struct inode *inode) 982 - { 983 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 984 - int ret = 0; 985 - 986 - mutex_lock(&zi->i_truncate_mutex); 987 - 988 - if (!zi->i_wr_refcnt) { 989 - struct zonefs_sb_info *sbi = ZONEFS_SB(inode->i_sb); 990 - unsigned int wro = atomic_inc_return(&sbi->s_wro_seq_files); 991 - 992 - if (sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) { 993 - 994 - if (sbi->s_max_wro_seq_files 995 - && wro > sbi->s_max_wro_seq_files) { 996 - atomic_dec(&sbi->s_wro_seq_files); 997 - ret = -EBUSY; 998 - goto unlock; 999 - } 1000 - 1001 - if (i_size_read(inode) < zi->i_max_size) { 1002 - ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_OPEN); 1003 - if (ret) { 1004 - atomic_dec(&sbi->s_wro_seq_files); 1005 - goto unlock; 1006 - } 1007 - zi->i_flags |= ZONEFS_ZONE_OPEN; 1008 - zonefs_account_active(inode); 1009 - } 1010 - } 1011 - } 1012 - 1013 - zi->i_wr_refcnt++; 1014 - 1015 - unlock: 1016 - mutex_unlock(&zi->i_truncate_mutex); 1017 - 1018 - return ret; 1019 - } 1020 - 1021 - static int zonefs_file_open(struct inode *inode, struct file *file) 1022 - { 1023 - int ret; 1024 - 1025 - ret = generic_file_open(inode, file); 1026 - if (ret) 1027 - return ret; 1028 - 1029 - if (zonefs_seq_file_need_wro(inode, file)) 1030 - return zonefs_seq_file_write_open(inode); 1031 - 1032 - return 0; 1033 - } 1034 - 1035 - static void zonefs_seq_file_write_close(struct inode *inode) 1036 - { 1037 - struct zonefs_inode_info *zi = ZONEFS_I(inode); 1038 - struct super_block *sb = inode->i_sb; 1039 - struct zonefs_sb_info *sbi = ZONEFS_SB(sb); 1040 - int ret = 0; 1041 - 1042 - mutex_lock(&zi->i_truncate_mutex); 1043 - 1044 - zi->i_wr_refcnt--; 1045 - if (zi->i_wr_refcnt) 1046 - goto unlock; 1047 - 1048 - /* 1049 - * The file zone may not be open anymore (e.g. the file was truncated to 1050 - * its maximum size or it was fully written). For this case, we only 1051 - * need to decrement the write open count. 1052 - */ 1053 - if (zi->i_flags & ZONEFS_ZONE_OPEN) { 1054 - ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_CLOSE); 1055 - if (ret) { 1056 - __zonefs_io_error(inode, false); 1057 - /* 1058 - * Leaving zones explicitly open may lead to a state 1059 - * where most zones cannot be written (zone resources 1060 - * exhausted). So take preventive action by remounting 1061 - * read-only. 1062 - */ 1063 - if (zi->i_flags & ZONEFS_ZONE_OPEN && 1064 - !(sb->s_flags & SB_RDONLY)) { 1065 - zonefs_warn(sb, 1066 - "closing zone at %llu failed %d\n", 1067 - zi->i_zsector, ret); 1068 - zonefs_warn(sb, 1069 - "remounting filesystem read-only\n"); 1070 - sb->s_flags |= SB_RDONLY; 1071 - } 1072 - goto unlock; 1073 - } 1074 - 1075 - zi->i_flags &= ~ZONEFS_ZONE_OPEN; 1076 - zonefs_account_active(inode); 1077 - } 1078 - 1079 - atomic_dec(&sbi->s_wro_seq_files); 1080 - 1081 - unlock: 1082 - mutex_unlock(&zi->i_truncate_mutex); 1083 - } 1084 - 1085 - static int zonefs_file_release(struct inode *inode, struct file *file) 1086 - { 1087 - /* 1088 - * If we explicitly open a zone we must close it again as well, but the 1089 - * zone management operation can fail (either due to an IO error or as 1090 - * the zone has gone offline or read-only). Make sure we don't fail the 1091 - * close(2) for user-space. 1092 - */ 1093 - if (zonefs_seq_file_need_wro(inode, file)) 1094 - zonefs_seq_file_write_close(inode); 1095 - 1096 - return 0; 1097 - } 1098 - 1099 - static const struct file_operations zonefs_file_operations = { 1100 - .open = zonefs_file_open, 1101 - .release = zonefs_file_release, 1102 - .fsync = zonefs_file_fsync, 1103 - .mmap = zonefs_file_mmap, 1104 - .llseek = zonefs_file_llseek, 1105 - .read_iter = zonefs_file_read_iter, 1106 - .write_iter = zonefs_file_write_iter, 1107 - .splice_read = generic_file_splice_read, 1108 - .splice_write = iter_file_splice_write, 1109 - .iopoll = iocb_bio_iopoll, 1110 - }; 1111 528 1112 529 static struct kmem_cache *zonefs_inode_cachep; 1113 530 ··· 505 1408 return zonefs_parse_options(sb, data); 506 1409 } 507 1410 508 - static const struct super_operations zonefs_sops = { 509 - .alloc_inode = zonefs_alloc_inode, 510 - .free_inode = zonefs_free_inode, 511 - .statfs = zonefs_statfs, 512 - .remount_fs = zonefs_remount, 513 - .show_options = zonefs_show_options, 514 - }; 1411 + static int zonefs_inode_setattr(struct user_namespace *mnt_userns, 1412 + struct dentry *dentry, struct iattr *iattr) 1413 + { 1414 + struct inode *inode = d_inode(dentry); 1415 + int ret; 1416 + 1417 + if (unlikely(IS_IMMUTABLE(inode))) 1418 + return -EPERM; 1419 + 1420 + ret = setattr_prepare(&init_user_ns, dentry, iattr); 1421 + if (ret) 1422 + return ret; 1423 + 1424 + /* 1425 + * Since files and directories cannot be created nor deleted, do not 1426 + * allow setting any write attributes on the sub-directories grouping 1427 + * files by zone type. 1428 + */ 1429 + if ((iattr->ia_valid & ATTR_MODE) && S_ISDIR(inode->i_mode) && 1430 + (iattr->ia_mode & 0222)) 1431 + return -EPERM; 1432 + 1433 + if (((iattr->ia_valid & ATTR_UID) && 1434 + !uid_eq(iattr->ia_uid, inode->i_uid)) || 1435 + ((iattr->ia_valid & ATTR_GID) && 1436 + !gid_eq(iattr->ia_gid, inode->i_gid))) { 1437 + ret = dquot_transfer(mnt_userns, inode, iattr); 1438 + if (ret) 1439 + return ret; 1440 + } 1441 + 1442 + if (iattr->ia_valid & ATTR_SIZE) { 1443 + ret = zonefs_file_truncate(inode, iattr->ia_size); 1444 + if (ret) 1445 + return ret; 1446 + } 1447 + 1448 + setattr_copy(&init_user_ns, inode, iattr); 1449 + 1450 + return 0; 1451 + } 515 1452 516 1453 static const struct inode_operations zonefs_dir_inode_operations = { 517 1454 .lookup = simple_lookup, ··· 564 1433 set_nlink(inode, 2); 565 1434 inc_nlink(parent); 566 1435 } 1436 + 1437 + static const struct inode_operations zonefs_file_inode_operations = { 1438 + .setattr = zonefs_inode_setattr, 1439 + }; 567 1440 568 1441 static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone, 569 1442 enum zonefs_ztype type) ··· 919 1784 920 1785 return ret; 921 1786 } 1787 + 1788 + static const struct super_operations zonefs_sops = { 1789 + .alloc_inode = zonefs_alloc_inode, 1790 + .free_inode = zonefs_free_inode, 1791 + .statfs = zonefs_statfs, 1792 + .remount_fs = zonefs_remount, 1793 + .show_options = zonefs_show_options, 1794 + }; 922 1795 923 1796 /* 924 1797 * Check that the device is zoned. If it is, get the list of zones and create
+22
fs/zonefs/zonefs.h
··· 209 209 #define zonefs_warn(sb, format, args...) \ 210 210 pr_warn("zonefs (%s) WARNING: " format, sb->s_id, ## args) 211 211 212 + /* In super.c */ 213 + void zonefs_account_active(struct inode *inode); 214 + int zonefs_zone_mgmt(struct inode *inode, enum req_op op); 215 + void zonefs_i_size_write(struct inode *inode, loff_t isize); 216 + void zonefs_update_stats(struct inode *inode, loff_t new_isize); 217 + void __zonefs_io_error(struct inode *inode, bool write); 218 + 219 + static inline void zonefs_io_error(struct inode *inode, bool write) 220 + { 221 + struct zonefs_inode_info *zi = ZONEFS_I(inode); 222 + 223 + mutex_lock(&zi->i_truncate_mutex); 224 + __zonefs_io_error(inode, write); 225 + mutex_unlock(&zi->i_truncate_mutex); 226 + } 227 + 228 + /* In file.c */ 229 + extern const struct address_space_operations zonefs_file_aops; 230 + extern const struct file_operations zonefs_file_operations; 231 + int zonefs_file_truncate(struct inode *inode, loff_t isize); 232 + 233 + /* In sysfs.c */ 212 234 int zonefs_sysfs_register(struct super_block *sb); 213 235 void zonefs_sysfs_unregister(struct super_block *sb); 214 236 int zonefs_sysfs_init(void);