Skip to content

Commit 9ff0512

Browse files
konistorvalds
authored andcommitted
nilfs2: segment constructor
This adds the segment constructor (also called log writer). The segment constructor collects dirty buffers for every dirty inode, makes summaries of the buffers, assigns disk block addresses to the buffers, and then submits BIOs for the buffers. Signed-off-by: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 64b5a32 commit 9ff0512

File tree

4 files changed

+3577
-3
lines changed

4 files changed

+3577
-3
lines changed

fs/nilfs2/file.c

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,66 @@ nilfs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
7373
return ret;
7474
}
7575

76-
static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct page *page)
76+
static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
7777
{
78-
if (!(vma->vm_flags & (VM_WRITE | VM_MAYWRITE)))
79-
return -EPERM;
78+
struct page *page = vmf->page;
79+
struct inode *inode = vma->vm_file->f_dentry->d_inode;
80+
struct nilfs_transaction_info ti;
81+
int ret;
82+
83+
if (unlikely(nilfs_near_disk_full(NILFS_SB(inode->i_sb)->s_nilfs)))
84+
return VM_FAULT_SIGBUS; /* -ENOSPC */
85+
86+
lock_page(page);
87+
if (page->mapping != inode->i_mapping ||
88+
page_offset(page) >= i_size_read(inode) || !PageUptodate(page)) {
89+
unlock_page(page);
90+
return VM_FAULT_NOPAGE; /* make the VM retry the fault */
91+
}
92+
93+
/*
94+
* check to see if the page is mapped already (no holes)
95+
*/
96+
if (PageMappedToDisk(page)) {
97+
unlock_page(page);
98+
goto mapped;
99+
}
100+
if (page_has_buffers(page)) {
101+
struct buffer_head *bh, *head;
102+
int fully_mapped = 1;
103+
104+
bh = head = page_buffers(page);
105+
do {
106+
if (!buffer_mapped(bh)) {
107+
fully_mapped = 0;
108+
break;
109+
}
110+
} while (bh = bh->b_this_page, bh != head);
111+
112+
if (fully_mapped) {
113+
SetPageMappedToDisk(page);
114+
unlock_page(page);
115+
goto mapped;
116+
}
117+
}
118+
unlock_page(page);
119+
120+
/*
121+
* fill hole blocks
122+
*/
123+
ret = nilfs_transaction_begin(inode->i_sb, &ti, 1);
124+
/* never returns -ENOMEM, but may return -ENOSPC */
125+
if (unlikely(ret))
126+
return VM_FAULT_SIGBUS;
127+
128+
ret = block_page_mkwrite(vma, vmf, nilfs_get_block);
129+
if (unlikely(ret)) {
130+
nilfs_transaction_abort(inode->i_sb);
131+
return ret;
132+
}
133+
nilfs_transaction_commit(inode->i_sb);
134+
135+
mapped:
80136
SetPageChecked(page);
81137
wait_on_page_writeback(page);
82138
return 0;

fs/nilfs2/seglist.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* seglist.h - expediential structure and routines to handle list of segments
3+
* (would be removed in a future release)
4+
*
5+
* Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* Written by Ryusuke Konishi <[email protected]>
22+
*
23+
*/
24+
#ifndef _NILFS_SEGLIST_H
25+
#define _NILFS_SEGLIST_H
26+
27+
#include <linux/fs.h>
28+
#include <linux/buffer_head.h>
29+
#include <linux/nilfs2_fs.h>
30+
#include "sufile.h"
31+
32+
struct nilfs_segment_entry {
33+
__u64 segnum;
34+
35+
#define NILFS_SLH_FREED 0x0001 /* The segment was freed provisonally.
36+
It must be cancelled if
37+
construction aborted */
38+
39+
unsigned flags;
40+
struct list_head list;
41+
struct buffer_head *bh_su;
42+
struct nilfs_segment_usage *raw_su;
43+
};
44+
45+
46+
void nilfs_dispose_segment_list(struct list_head *);
47+
48+
static inline struct nilfs_segment_entry *
49+
nilfs_alloc_segment_entry(__u64 segnum)
50+
{
51+
struct nilfs_segment_entry *ent = kmalloc(sizeof(*ent), GFP_NOFS);
52+
53+
if (likely(ent)) {
54+
ent->segnum = segnum;
55+
ent->flags = 0;
56+
ent->bh_su = NULL;
57+
ent->raw_su = NULL;
58+
INIT_LIST_HEAD(&ent->list);
59+
}
60+
return ent;
61+
}
62+
63+
static inline int nilfs_open_segment_entry(struct nilfs_segment_entry *ent,
64+
struct inode *sufile)
65+
{
66+
return nilfs_sufile_get_segment_usage(sufile, ent->segnum,
67+
&ent->raw_su, &ent->bh_su);
68+
}
69+
70+
static inline void nilfs_close_segment_entry(struct nilfs_segment_entry *ent,
71+
struct inode *sufile)
72+
{
73+
if (!ent->bh_su)
74+
return;
75+
nilfs_sufile_put_segment_usage(sufile, ent->segnum, ent->bh_su);
76+
ent->bh_su = NULL;
77+
ent->raw_su = NULL;
78+
}
79+
80+
static inline void nilfs_free_segment_entry(struct nilfs_segment_entry *ent)
81+
{
82+
kfree(ent);
83+
}
84+
85+
#endif /* _NILFS_SEGLIST_H */

0 commit comments

Comments
 (0)