node.c (769ec6e5b7d4a8115447736871be8bffaaba3a7d) node.c (9be32d72becca41d7d9b010d7d9be1d39489414f)
1/*
2 * fs/f2fs/node.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
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 version 2 as

--- 133 unchanged lines hidden (view full) ---

142static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
143 struct nat_entry *ne)
144{
145 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
146 struct nat_entry_set *head;
147
148 if (get_nat_flag(ne, IS_DIRTY))
149 return;
1/*
2 * fs/f2fs/node.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
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 version 2 as

--- 133 unchanged lines hidden (view full) ---

142static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
143 struct nat_entry *ne)
144{
145 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
146 struct nat_entry_set *head;
147
148 if (get_nat_flag(ne, IS_DIRTY))
149 return;
150retry:
150
151 head = radix_tree_lookup(&nm_i->nat_set_root, set);
152 if (!head) {
153 head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_ATOMIC);
154
155 INIT_LIST_HEAD(&head->entry_list);
156 INIT_LIST_HEAD(&head->set_list);
157 head->set = set;
158 head->entry_cnt = 0;
151 head = radix_tree_lookup(&nm_i->nat_set_root, set);
152 if (!head) {
153 head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_ATOMIC);
154
155 INIT_LIST_HEAD(&head->entry_list);
156 INIT_LIST_HEAD(&head->set_list);
157 head->set = set;
158 head->entry_cnt = 0;
159
160 if (radix_tree_insert(&nm_i->nat_set_root, set, head)) {
161 kmem_cache_free(nat_entry_set_slab, head);
162 goto retry;
163 }
159 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
164 }
165 list_move_tail(&ne->list, &head->entry_list);
166 nm_i->dirty_nat_cnt++;
167 head->entry_cnt++;
168 set_nat_flag(ne, IS_DIRTY, true);
169}
170
171static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,

--- 61 unchanged lines hidden (view full) ---

233 up_read(&nm_i->nat_tree_lock);
234 return need_update;
235}
236
237static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid)
238{
239 struct nat_entry *new;
240
160 }
161 list_move_tail(&ne->list, &head->entry_list);
162 nm_i->dirty_nat_cnt++;
163 head->entry_cnt++;
164 set_nat_flag(ne, IS_DIRTY, true);
165}
166
167static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,

--- 61 unchanged lines hidden (view full) ---

229 up_read(&nm_i->nat_tree_lock);
230 return need_update;
231}
232
233static struct nat_entry *grab_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid)
234{
235 struct nat_entry *new;
236
241 new = kmem_cache_alloc(nat_entry_slab, GFP_ATOMIC);
242 if (!new)
243 return NULL;
244 if (radix_tree_insert(&nm_i->nat_root, nid, new)) {
245 kmem_cache_free(nat_entry_slab, new);
246 return NULL;
247 }
237 new = f2fs_kmem_cache_alloc(nat_entry_slab, GFP_ATOMIC);
238 f2fs_radix_tree_insert(&nm_i->nat_root, nid, new);
248 memset(new, 0, sizeof(struct nat_entry));
249 nat_set_nid(new, nid);
250 nat_reset_flag(new);
251 list_add_tail(&new->list, &nm_i->nat_entries);
252 nm_i->nat_cnt++;
253 return new;
254}
255
256static void cache_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid,
257 struct f2fs_nat_entry *ne)
258{
259 struct nat_entry *e;
239 memset(new, 0, sizeof(struct nat_entry));
240 nat_set_nid(new, nid);
241 nat_reset_flag(new);
242 list_add_tail(&new->list, &nm_i->nat_entries);
243 nm_i->nat_cnt++;
244 return new;
245}
246
247static void cache_nat_entry(struct f2fs_nm_info *nm_i, nid_t nid,
248 struct f2fs_nat_entry *ne)
249{
250 struct nat_entry *e;
260retry:
251
261 down_write(&nm_i->nat_tree_lock);
262 e = __lookup_nat_cache(nm_i, nid);
263 if (!e) {
264 e = grab_nat_entry(nm_i, nid);
252 down_write(&nm_i->nat_tree_lock);
253 e = __lookup_nat_cache(nm_i, nid);
254 if (!e) {
255 e = grab_nat_entry(nm_i, nid);
265 if (!e) {
266 up_write(&nm_i->nat_tree_lock);
267 goto retry;
268 }
269 node_info_from_raw_nat(&e->ni, ne);
270 }
271 up_write(&nm_i->nat_tree_lock);
272}
273
274static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
275 block_t new_blkaddr, bool fsync_done)
276{
277 struct f2fs_nm_info *nm_i = NM_I(sbi);
278 struct nat_entry *e;
256 node_info_from_raw_nat(&e->ni, ne);
257 }
258 up_write(&nm_i->nat_tree_lock);
259}
260
261static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
262 block_t new_blkaddr, bool fsync_done)
263{
264 struct f2fs_nm_info *nm_i = NM_I(sbi);
265 struct nat_entry *e;
279retry:
266
280 down_write(&nm_i->nat_tree_lock);
281 e = __lookup_nat_cache(nm_i, ni->nid);
282 if (!e) {
283 e = grab_nat_entry(nm_i, ni->nid);
267 down_write(&nm_i->nat_tree_lock);
268 e = __lookup_nat_cache(nm_i, ni->nid);
269 if (!e) {
270 e = grab_nat_entry(nm_i, ni->nid);
284 if (!e) {
285 up_write(&nm_i->nat_tree_lock);
286 goto retry;
287 }
288 e->ni = *ni;
289 f2fs_bug_on(sbi, ni->blk_addr == NEW_ADDR);
290 } else if (new_blkaddr == NEW_ADDR) {
291 /*
292 * when nid is reallocated,
293 * previous nat entry can be remained in nat cache.
294 * So, reinitialize it with new information.
295 */

--- 1532 unchanged lines hidden (view full) ---

1828
1829 mutex_lock(&curseg->curseg_mutex);
1830 for (i = 0; i < nats_in_cursum(sum); i++) {
1831 struct nat_entry *ne;
1832 struct f2fs_nat_entry raw_ne;
1833 nid_t nid = le32_to_cpu(nid_in_journal(sum, i));
1834
1835 raw_ne = nat_in_journal(sum, i);
271 e->ni = *ni;
272 f2fs_bug_on(sbi, ni->blk_addr == NEW_ADDR);
273 } else if (new_blkaddr == NEW_ADDR) {
274 /*
275 * when nid is reallocated,
276 * previous nat entry can be remained in nat cache.
277 * So, reinitialize it with new information.
278 */

--- 1532 unchanged lines hidden (view full) ---

1811
1812 mutex_lock(&curseg->curseg_mutex);
1813 for (i = 0; i < nats_in_cursum(sum); i++) {
1814 struct nat_entry *ne;
1815 struct f2fs_nat_entry raw_ne;
1816 nid_t nid = le32_to_cpu(nid_in_journal(sum, i));
1817
1818 raw_ne = nat_in_journal(sum, i);
1836retry:
1819
1837 down_write(&nm_i->nat_tree_lock);
1838 ne = __lookup_nat_cache(nm_i, nid);
1820 down_write(&nm_i->nat_tree_lock);
1821 ne = __lookup_nat_cache(nm_i, nid);
1839 if (ne)
1840 goto found;
1841
1842 ne = grab_nat_entry(nm_i, nid);
1843 if (!ne) {
1822 if (!ne) {
1844 up_write(&nm_i->nat_tree_lock);
1845 goto retry;
1823 ne = grab_nat_entry(nm_i, nid);
1824 node_info_from_raw_nat(&ne->ni, &raw_ne);
1846 }
1825 }
1847 node_info_from_raw_nat(&ne->ni, &raw_ne);
1848found:
1849 __set_nat_cache_dirty(nm_i, ne);
1850 up_write(&nm_i->nat_tree_lock);
1851 }
1852 update_nats_in_cursum(sum, -i);
1853 mutex_unlock(&curseg->curseg_mutex);
1854}
1855
1856static void __adjust_nat_entry_set(struct nat_entry_set *nes,

--- 257 unchanged lines hidden ---
1826 __set_nat_cache_dirty(nm_i, ne);
1827 up_write(&nm_i->nat_tree_lock);
1828 }
1829 update_nats_in_cursum(sum, -i);
1830 mutex_unlock(&curseg->curseg_mutex);
1831}
1832
1833static void __adjust_nat_entry_set(struct nat_entry_set *nes,

--- 257 unchanged lines hidden ---