2 * inode.c - NILFS inode operations.
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
24 #include <linux/buffer_head.h>
25 #include <linux/mpage.h>
26 #include <linux/writeback.h>
27 #include <linux/uio.h>
37 * nilfs_get_block() - get a file block on the filesystem (callback function)
38 * @inode - inode struct of the target file
39 * @blkoff - file block number
40 * @bh_result - buffer head to be mapped on
41 * @create - indicate whether allocating the block or not when it has not
44 * This function does not issue actual read request of the specified data
45 * block. It is done by VFS.
46 * Bulk read for direct-io is not supported yet. (should be supported)
48 int nilfs_get_block(struct inode *inode, sector_t blkoff,
49 struct buffer_head *bh_result, int create)
51 struct nilfs_inode_info *ii = NILFS_I(inode);
52 unsigned long blknum = 0;
54 struct inode *dat = nilfs_dat_inode(NILFS_I_NILFS(inode));
56 /* This exclusion control is a workaround; should be revised */
57 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
58 ret = nilfs_bmap_lookup(ii->i_bmap, (unsigned long)blkoff, &blknum);
59 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
60 if (ret == 0) { /* found */
61 map_bh(bh_result, inode->i_sb, blknum);
64 if (unlikely(ret == 1)) {
65 printk(KERN_ERR "nilfs_get_block: bmap_lookup returns "
66 "buffer_head pointer (blkoff=%llu, blknum=%lu)\n",
67 (unsigned long long)blkoff, blknum);
70 /* data block was not found */
71 if (ret == -ENOENT && create) {
72 struct nilfs_transaction_info ti;
74 bh_result->b_blocknr = 0;
75 err = nilfs_transaction_begin(inode->i_sb, &ti, 1);
78 err = nilfs_bmap_insert(ii->i_bmap, (unsigned long)blkoff,
79 (unsigned long)bh_result);
80 nilfs_transaction_end(inode->i_sb, !err);
81 if (unlikely(err != 0)) {
84 * The get_block() function could be called
85 * from multiple callers for an inode.
86 * However, the page having this block must
87 * be locked in this case.
90 "nilfs_get_block: a race condition "
91 "while inserting a data block. "
92 "(inode number=%lu, file block "
95 (unsigned long long)blkoff);
97 } else if (err == -EINVAL) {
98 nilfs_error(inode->i_sb, __func__,
99 "broken bmap (inode=%lu)\n",
105 /* Error handling should be detailed */
106 set_buffer_new(bh_result);
107 map_bh(bh_result, inode->i_sb, 0); /* dbn must be changed
109 } else if (ret == -ENOENT) {
110 /* not found is not error (e.g. hole); must return without
111 the mapped state flag. */
122 * nilfs_readpage() - implement readpage() method of nilfs_aops {}
123 * address_space_operations.
124 * @file - file struct of the file to be read
125 * @page - the page to be read
127 static int nilfs_readpage(struct file *file, struct page *page)
129 return mpage_readpage(page, nilfs_get_block);
133 * nilfs_readpages() - implement readpages() method of nilfs_aops {}
134 * address_space_operations.
135 * @file - file struct of the file to be read
136 * @mapping - address_space struct used for reading multiple pages
137 * @pages - the pages to be read
138 * @nr_pages - number of pages to be read
140 static int nilfs_readpages(struct file *file, struct address_space *mapping,
141 struct list_head *pages, unsigned nr_pages)
143 return mpage_readpages(mapping, pages, nr_pages, nilfs_get_block);
146 static int nilfs_writepages(struct address_space *mapping,
147 struct writeback_control *wbc)
149 struct inode *inode = mapping->host;
152 if (wbc->sync_mode == WB_SYNC_ALL)
153 err = nilfs_construct_dsync_segment(inode->i_sb, inode,
159 static int nilfs_writepage(struct page *page, struct writeback_control *wbc)
161 struct inode *inode = page->mapping->host;
164 redirty_page_for_writepage(wbc, page);
167 if (wbc->sync_mode == WB_SYNC_ALL) {
168 err = nilfs_construct_segment(inode->i_sb);
171 } else if (wbc->for_reclaim)
172 nilfs_flush_segment(inode->i_sb, inode->i_ino);
177 static int nilfs_set_page_dirty(struct page *page)
179 int ret = __set_page_dirty_buffers(page);
182 struct inode *inode = page->mapping->host;
183 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
184 unsigned nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits);
186 nilfs_set_file_dirty(sbi, inode, nr_dirty);
191 static int nilfs_write_begin(struct file *file, struct address_space *mapping,
192 loff_t pos, unsigned len, unsigned flags,
193 struct page **pagep, void **fsdata)
196 struct inode *inode = mapping->host;
197 int err = nilfs_transaction_begin(inode->i_sb, NULL, 1);
203 err = block_write_begin(file, mapping, pos, len, flags, pagep,
204 fsdata, nilfs_get_block);
206 nilfs_transaction_end(inode->i_sb, 0);
210 static int nilfs_write_end(struct file *file, struct address_space *mapping,
211 loff_t pos, unsigned len, unsigned copied,
212 struct page *page, void *fsdata)
214 struct inode *inode = mapping->host;
215 unsigned start = pos & (PAGE_CACHE_SIZE - 1);
219 nr_dirty = nilfs_page_count_clean_buffers(page, start,
221 copied = generic_write_end(file, mapping, pos, len, copied, page,
223 nilfs_set_file_dirty(NILFS_SB(inode->i_sb), inode, nr_dirty);
224 err = nilfs_transaction_end(inode->i_sb, 1);
225 return err ? : copied;
229 nilfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
230 loff_t offset, unsigned long nr_segs)
232 struct file *file = iocb->ki_filp;
233 struct inode *inode = file->f_mapping->host;
239 /* Needs synchronization with the cleaner */
240 size = blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
241 offset, nr_segs, nilfs_get_block, NULL);
245 struct address_space_operations nilfs_aops = {
246 .writepage = nilfs_writepage,
247 .readpage = nilfs_readpage,
248 /* .sync_page = nilfs_sync_page, */
249 .writepages = nilfs_writepages,
250 .set_page_dirty = nilfs_set_page_dirty,
251 .readpages = nilfs_readpages,
252 .write_begin = nilfs_write_begin,
253 .write_end = nilfs_write_end,
254 /* .releasepage = nilfs_releasepage, */
255 .invalidatepage = block_invalidatepage,
256 .direct_IO = nilfs_direct_IO,
259 struct inode *nilfs_new_inode(struct inode *dir, int mode)
261 struct super_block *sb = dir->i_sb;
262 struct nilfs_sb_info *sbi = NILFS_SB(sb);
264 struct nilfs_inode_info *ii;
268 inode = new_inode(sb);
269 if (unlikely(!inode))
272 mapping_set_gfp_mask(inode->i_mapping,
273 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
276 ii->i_state = 1 << NILFS_I_NEW;
278 err = nilfs_ifile_create_inode(sbi->s_ifile, &ino, &ii->i_bh);
280 goto failed_ifile_create_inode;
281 /* reference count of i_bh inherits from nilfs_mdt_read_block() */
283 atomic_inc(&sbi->s_inodes_count);
285 inode->i_uid = current_fsuid();
286 if (dir->i_mode & S_ISGID) {
287 inode->i_gid = dir->i_gid;
291 inode->i_gid = current_fsgid();
293 inode->i_mode = mode;
295 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
297 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) {
298 err = nilfs_bmap_read(ii->i_bmap, NULL);
302 set_bit(NILFS_I_BMAP, &ii->i_state);
303 /* No lock is needed; iget() ensures it. */
306 ii->i_flags = NILFS_I(dir)->i_flags;
308 ii->i_flags &= ~(NILFS_IMMUTABLE_FL | NILFS_APPEND_FL);
310 ii->i_flags &= ~NILFS_DIRSYNC_FL;
312 /* ii->i_file_acl = 0; */
313 /* ii->i_dir_acl = 0; */
315 ii->i_dir_start_lookup = 0;
316 #ifdef CONFIG_NILFS_FS_POSIX_ACL
318 ii->i_default_acl = NULL;
321 nilfs_set_inode_flags(inode);
322 spin_lock(&sbi->s_next_gen_lock);
323 inode->i_generation = sbi->s_next_generation++;
324 spin_unlock(&sbi->s_next_gen_lock);
325 insert_inode_hash(inode);
327 err = nilfs_init_acl(inode, dir);
329 goto failed_acl; /* never occur. When supporting
330 nilfs_init_acl(), proper cancellation of
331 above jobs should be considered */
333 mark_inode_dirty(inode);
339 iput(inode); /* raw_inode will be deleted through
340 generic_delete_inode() */
343 failed_ifile_create_inode:
344 make_bad_inode(inode);
345 iput(inode); /* if i_nlink == 1, generic_forget_inode() will be
351 void nilfs_free_inode(struct inode *inode)
353 struct super_block *sb = inode->i_sb;
354 struct nilfs_sb_info *sbi = NILFS_SB(sb);
357 /* XXX: check error code? Is there any thing I can do? */
358 (void) nilfs_ifile_delete_inode(sbi->s_ifile, inode->i_ino);
359 atomic_dec(&sbi->s_inodes_count);
362 void nilfs_set_inode_flags(struct inode *inode)
364 unsigned int flags = NILFS_I(inode)->i_flags;
366 inode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME |
368 if (flags & NILFS_SYNC_FL)
369 inode->i_flags |= S_SYNC;
370 if (flags & NILFS_APPEND_FL)
371 inode->i_flags |= S_APPEND;
372 if (flags & NILFS_IMMUTABLE_FL)
373 inode->i_flags |= S_IMMUTABLE;
374 #ifndef NILFS_ATIME_DISABLE
375 if (flags & NILFS_NOATIME_FL)
377 inode->i_flags |= S_NOATIME;
378 if (flags & NILFS_DIRSYNC_FL)
379 inode->i_flags |= S_DIRSYNC;
380 mapping_set_gfp_mask(inode->i_mapping,
381 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
384 int nilfs_read_inode_common(struct inode *inode,
385 struct nilfs_inode *raw_inode)
387 struct nilfs_inode_info *ii = NILFS_I(inode);
390 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
391 inode->i_uid = (uid_t)le32_to_cpu(raw_inode->i_uid);
392 inode->i_gid = (gid_t)le32_to_cpu(raw_inode->i_gid);
393 inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
394 inode->i_size = le64_to_cpu(raw_inode->i_size);
395 inode->i_atime.tv_sec = le64_to_cpu(raw_inode->i_mtime);
396 inode->i_ctime.tv_sec = le64_to_cpu(raw_inode->i_ctime);
397 inode->i_mtime.tv_sec = le64_to_cpu(raw_inode->i_mtime);
398 inode->i_atime.tv_nsec = 0;
399 inode->i_ctime.tv_nsec = 0;
400 inode->i_mtime.tv_nsec = 0;
401 ii->i_dtime = le64_to_cpu(raw_inode->i_dtime);
402 if (inode->i_nlink == 0 && (inode->i_mode == 0 || ii->i_dtime))
403 return -EINVAL; /* this inode is deleted */
405 inode->i_blocks = le64_to_cpu(raw_inode->i_blocks);
406 ii->i_flags = le32_to_cpu(raw_inode->i_flags);
408 ii->i_file_acl = le32_to_cpu(raw_inode->i_file_acl);
409 ii->i_dir_acl = S_ISREG(inode->i_mode) ?
410 0 : le32_to_cpu(raw_inode->i_dir_acl);
413 inode->i_generation = le32_to_cpu(raw_inode->i_generation);
415 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
416 S_ISLNK(inode->i_mode)) {
417 err = nilfs_bmap_read(ii->i_bmap, raw_inode);
420 set_bit(NILFS_I_BMAP, &ii->i_state);
421 /* No lock is needed; iget() ensures it. */
426 static int nilfs_read_sketch_inode(struct inode *inode)
428 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
431 if (sbi->s_snapshot_cno) {
432 struct the_nilfs *nilfs = sbi->s_nilfs;
433 struct buffer_head *bh_cp;
434 struct nilfs_checkpoint *raw_cp;
436 err = nilfs_cpfile_get_checkpoint(
437 nilfs->ns_cpfile, sbi->s_snapshot_cno, 0, &raw_cp,
440 if (!nilfs_checkpoint_sketch(raw_cp))
442 nilfs_cpfile_put_checkpoint(
443 nilfs->ns_cpfile, sbi->s_snapshot_cno, bh_cp);
445 inode->i_flags |= S_NOCMTIME;
450 static int __nilfs_read_inode(struct super_block *sb, unsigned long ino,
453 struct nilfs_sb_info *sbi = NILFS_SB(sb);
454 struct inode *dat = nilfs_dat_inode(sbi->s_nilfs);
455 struct buffer_head *bh;
456 struct nilfs_inode *raw_inode;
459 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
460 err = nilfs_ifile_get_inode_block(sbi->s_ifile, ino, &bh);
464 raw_inode = nilfs_ifile_map_inode(sbi->s_ifile, ino, bh);
466 #ifdef CONFIG_NILFS_FS_POSIX_ACL
467 ii->i_acl = NILFS_ACL_NOT_CACHED;
468 ii->i_default_acl = NILFS_ACL_NOT_CACHED;
470 if (nilfs_read_inode_common(inode, raw_inode))
473 if (S_ISREG(inode->i_mode)) {
474 inode->i_op = &nilfs_file_inode_operations;
475 inode->i_fop = &nilfs_file_operations;
476 inode->i_mapping->a_ops = &nilfs_aops;
477 if (unlikely(inode->i_ino == NILFS_SKETCH_INO)) {
478 err = nilfs_read_sketch_inode(inode);
482 } else if (S_ISDIR(inode->i_mode)) {
483 inode->i_op = &nilfs_dir_inode_operations;
484 inode->i_fop = &nilfs_dir_operations;
485 inode->i_mapping->a_ops = &nilfs_aops;
486 } else if (S_ISLNK(inode->i_mode)) {
487 inode->i_op = &nilfs_symlink_inode_operations;
488 inode->i_mapping->a_ops = &nilfs_aops;
490 inode->i_op = &nilfs_special_inode_operations;
492 inode, inode->i_mode,
493 new_decode_dev(le64_to_cpu(raw_inode->i_device_code)));
495 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, bh);
497 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
498 nilfs_set_inode_flags(inode);
502 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, bh);
506 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
510 struct inode *nilfs_iget(struct super_block *sb, unsigned long ino)
515 inode = iget_locked(sb, ino);
516 if (unlikely(!inode))
517 return ERR_PTR(-ENOMEM);
518 if (!(inode->i_state & I_NEW))
521 err = __nilfs_read_inode(sb, ino, inode);
526 unlock_new_inode(inode);
530 void nilfs_write_inode_common(struct inode *inode,
531 struct nilfs_inode *raw_inode, int has_bmap)
533 struct nilfs_inode_info *ii = NILFS_I(inode);
535 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
536 raw_inode->i_uid = cpu_to_le32(inode->i_uid);
537 raw_inode->i_gid = cpu_to_le32(inode->i_gid);
538 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
539 raw_inode->i_size = cpu_to_le64(inode->i_size);
540 raw_inode->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);
541 raw_inode->i_mtime = cpu_to_le64(inode->i_mtime.tv_sec);
542 raw_inode->i_blocks = cpu_to_le64(inode->i_blocks);
544 raw_inode->i_dtime = cpu_to_le64(ii->i_dtime);
545 raw_inode->i_flags = cpu_to_le32(ii->i_flags);
546 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
549 nilfs_bmap_write(ii->i_bmap, raw_inode);
550 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
551 raw_inode->i_device_code =
552 cpu_to_le64(new_encode_dev(inode->i_rdev));
553 /* When extending inode, nilfs->ns_inode_size should be checked
554 for substitutions of appended fields */
557 void nilfs_update_inode(struct inode *inode, struct buffer_head *ibh)
559 ino_t ino = inode->i_ino;
560 struct nilfs_inode_info *ii = NILFS_I(inode);
561 struct super_block *sb = inode->i_sb;
562 struct nilfs_sb_info *sbi = NILFS_SB(sb);
563 struct nilfs_inode *raw_inode;
565 raw_inode = nilfs_ifile_map_inode(sbi->s_ifile, ino, ibh);
567 /* The buffer is guarded with lock_buffer() by the caller */
568 if (test_and_clear_bit(NILFS_I_NEW, &ii->i_state))
569 memset(raw_inode, 0, NILFS_MDT(sbi->s_ifile)->mi_entry_size);
570 set_bit(NILFS_I_INODE_DIRTY, &ii->i_state);
572 nilfs_write_inode_common(inode, raw_inode, 0);
573 /* XXX: call with has_bmap = 0 is a workaround to avoid
574 deadlock of bmap. This delays update of i_bmap to just
576 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, ibh);
579 #define NILFS_MAX_TRUNCATE_BLOCKS 16384 /* 64MB for 4KB block */
581 static void nilfs_truncate_bmap(struct nilfs_inode_info *ii,
587 if (!test_bit(NILFS_I_BMAP, &ii->i_state))
590 ret = nilfs_bmap_last_key(ii->i_bmap, &b);
599 b -= min_t(unsigned long, NILFS_MAX_TRUNCATE_BLOCKS, b - from);
600 ret = nilfs_bmap_truncate(ii->i_bmap, b);
601 nilfs_relax_pressure_in_lock(ii->vfs_inode.i_sb);
602 if (!ret || (ret == -ENOMEM &&
603 nilfs_bmap_truncate(ii->i_bmap, b) == 0))
608 nilfs_error(ii->vfs_inode.i_sb, __func__,
609 "bmap is broken (ino=%lu)", ii->vfs_inode.i_ino);
611 nilfs_warning(ii->vfs_inode.i_sb, __func__,
612 "failed to truncate bmap (ino=%lu, err=%d)",
613 ii->vfs_inode.i_ino, ret);
616 void nilfs_truncate(struct inode *inode)
618 unsigned long blkoff;
619 unsigned int blocksize;
620 struct nilfs_transaction_info ti;
621 struct super_block *sb = inode->i_sb;
622 struct nilfs_inode_info *ii = NILFS_I(inode);
625 if (!test_bit(NILFS_I_BMAP, &ii->i_state))
627 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
630 blocksize = sb->s_blocksize;
631 blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
632 ret = nilfs_transaction_begin(sb, &ti, 0);
635 block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
637 nilfs_truncate_bmap(ii, blkoff);
639 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
641 nilfs_set_transaction_flag(NILFS_TI_SYNC);
643 nilfs_set_file_dirty(NILFS_SB(sb), inode, 0);
644 nilfs_transaction_end(sb, 1);
645 /* May construct a logical segment and may fail in sync mode.
646 But truncate has no return value. */
649 void nilfs_delete_inode(struct inode *inode)
651 struct nilfs_transaction_info ti;
652 struct super_block *sb = inode->i_sb;
653 struct nilfs_inode_info *ii = NILFS_I(inode);
656 if (unlikely(is_bad_inode(inode))) {
657 if (inode->i_data.nrpages)
658 truncate_inode_pages(&inode->i_data, 0);
662 err = nilfs_transaction_begin(sb, &ti, 0);
664 if (inode->i_data.nrpages)
665 truncate_inode_pages(&inode->i_data, 0);
667 nilfs_truncate_bmap(ii, 0);
668 nilfs_free_inode(inode);
669 /* nilfs_free_inode() marks inode buffer dirty */
671 nilfs_set_transaction_flag(NILFS_TI_SYNC);
672 nilfs_transaction_end(sb, 1);
673 /* May construct a logical segment and may fail in sync mode.
674 But delete_inode has no return value. */
677 int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)
679 struct nilfs_transaction_info ti;
680 struct inode *inode = dentry->d_inode;
681 struct super_block *sb = inode->i_sb;
684 err = inode_change_ok(inode, iattr);
688 err = nilfs_transaction_begin(sb, &ti, 0);
691 err = inode_setattr(inode, iattr);
692 if (!err && (iattr->ia_valid & ATTR_MODE))
693 err = nilfs_acl_chmod(inode);
694 err2 = nilfs_transaction_end(sb, 1);
698 int nilfs_load_inode_block(struct nilfs_sb_info *sbi, struct inode *inode,
699 struct buffer_head **pbh)
701 struct nilfs_inode_info *ii = NILFS_I(inode);
704 spin_lock(&sbi->s_inode_lock);
705 /* Caller of this function MUST lock s_inode_lock */
706 if (ii->i_bh == NULL) {
707 spin_unlock(&sbi->s_inode_lock);
708 err = nilfs_ifile_get_inode_block(sbi->s_ifile, inode->i_ino,
712 spin_lock(&sbi->s_inode_lock);
713 if (ii->i_bh == NULL)
723 spin_unlock(&sbi->s_inode_lock);
727 int nilfs_inode_dirty(struct inode *inode)
729 struct nilfs_inode_info *ii = NILFS_I(inode);
730 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
733 if (!list_empty(&ii->i_dirty)) {
734 spin_lock(&sbi->s_inode_lock);
735 ret = test_bit(NILFS_I_DIRTY, &ii->i_state) ||
736 test_bit(NILFS_I_BUSY, &ii->i_state);
737 spin_unlock(&sbi->s_inode_lock);
742 int nilfs_set_file_dirty(struct nilfs_sb_info *sbi, struct inode *inode,
745 struct nilfs_inode_info *ii = NILFS_I(inode);
747 atomic_add(nr_dirty, &sbi->s_nilfs->ns_ndirtyblks);
749 if (test_and_set_bit(NILFS_I_DIRTY, &ii->i_state) ||
750 unlikely(inode->i_ino == NILFS_SKETCH_INO))
753 spin_lock(&sbi->s_inode_lock);
754 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
755 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
756 /* Because this routine may race with nilfs_dispose_list(),
757 we have to check NILFS_I_QUEUED here, too. */
758 if (list_empty(&ii->i_dirty) && igrab(inode) == NULL) {
759 /* This will happen when somebody is freeing
761 nilfs_warning(sbi->s_super, __func__,
762 "cannot get inode (ino=%lu)\n",
764 spin_unlock(&sbi->s_inode_lock);
765 return -EINVAL; /* NILFS_I_DIRTY may remain for
768 list_del(&ii->i_dirty);
769 list_add_tail(&ii->i_dirty, &sbi->s_dirty_files);
770 set_bit(NILFS_I_QUEUED, &ii->i_state);
772 spin_unlock(&sbi->s_inode_lock);
776 int nilfs_mark_inode_dirty(struct inode *inode)
778 struct nilfs_sb_info *sbi = NILFS_SB(inode->i_sb);
779 struct buffer_head *ibh;
782 err = nilfs_load_inode_block(sbi, inode, &ibh);
784 nilfs_warning(inode->i_sb, __func__,
785 "failed to reget inode block.\n");
789 nilfs_update_inode(inode, ibh);
791 nilfs_mdt_mark_buffer_dirty(ibh);
792 nilfs_mdt_mark_dirty(sbi->s_ifile);
798 * nilfs_dirty_inode - reflect changes on given inode to an inode block.
799 * @inode: inode of the file to be registered.
801 * nilfs_dirty_inode() loads a inode block containing the specified
802 * @inode and copies data from a nilfs_inode to a corresponding inode
803 * entry in the inode block. This operation is excluded from the segment
804 * construction. This function can be called both as a single operation
805 * and as a part of indivisible file operations.
807 void nilfs_dirty_inode(struct inode *inode)
809 struct nilfs_transaction_info ti;
811 if (is_bad_inode(inode)) {
812 nilfs_warning(inode->i_sb, __func__,
813 "tried to mark bad_inode dirty. ignored.\n");
817 nilfs_transaction_begin(inode->i_sb, &ti, 0);
818 if (likely(inode->i_ino != NILFS_SKETCH_INO))
819 nilfs_mark_inode_dirty(inode);
820 nilfs_transaction_end(inode->i_sb, 1); /* never fails */