Skip to content

Commit d352ac6

Browse files
committed
Btrfs: add and improve comments
This improves the comments at the top of many functions. It didn't dive into the guts of functions because I was trying to avoid merging problems with the new allocator and back reference work. extent-tree.c and volumes.c were both skipped, and there is definitely more work todo in cleaning and commenting the code. Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 9a5e1ea commit d352ac6

25 files changed

Lines changed: 653 additions & 277 deletions

‎fs/btrfs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ifneq ($(KERNELRELEASE),)
44
obj-m := btrfs.o
55
btrfs-y := super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
66
file-item.o inode-item.o inode-map.o disk-io.o \
7-
transaction.o bit-radix.o inode.o file.o tree-defrag.o \
7+
transaction.o inode.o file.o tree-defrag.o \
88
extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
99
extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
1010
ref-cache.o export.o tree-log.o acl.o free-space-cache.o

‎fs/btrfs/TODO‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎fs/btrfs/async-thread.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,25 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
231231

232232
/*
233233
* if we pick a busy task, move the task to the end of the list.
234-
* hopefully this will keep things somewhat evenly balanced
234+
* hopefully this will keep things somewhat evenly balanced.
235+
* Do the move in batches based on the sequence number. This groups
236+
* requests submitted at roughly the same time onto the same worker.
235237
*/
236238
next = workers->worker_list.next;
237239
worker = list_entry(next, struct btrfs_worker_thread, worker_list);
238240
atomic_inc(&worker->num_pending);
239241
worker->sequence++;
242+
240243
if (worker->sequence % workers->idle_thresh == 0)
241244
list_move_tail(next, &workers->worker_list);
242245
return worker;
243246
}
244247

248+
/*
249+
* selects a worker thread to take the next job. This will either find
250+
* an idle worker, start a new worker up to the max count, or just return
251+
* one of the existing busy workers.
252+
*/
245253
static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
246254
{
247255
struct btrfs_worker_thread *worker;

‎fs/btrfs/async-thread.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ struct btrfs_workers {
6363
/* once a worker has this many requests or fewer, it is idle */
6464
int idle_thresh;
6565

66-
/* list with all the work threads */
66+
/* list with all the work threads. The workers on the idle thread
67+
* may be actively servicing jobs, but they haven't yet hit the
68+
* idle thresh limit above.
69+
*/
6770
struct list_head worker_list;
6871
struct list_head idle_list;
6972

7073
/* lock for finding the next worker thread to queue on */
7174
spinlock_t lock;
7275

73-
/* extra name for this worker */
76+
/* extra name for this worker, used for current->name */
7477
char *name;
7578
};
7679

‎fs/btrfs/bit-radix.c‎

Lines changed: 0 additions & 130 deletions
This file was deleted.

‎fs/btrfs/bit-radix.h‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,58 @@
2525

2626
/* in memory btrfs inode */
2727
struct btrfs_inode {
28+
/* which subvolume this inode belongs to */
2829
struct btrfs_root *root;
30+
31+
/* the block group preferred for allocations. This pointer is buggy
32+
* and needs to be replaced with a bytenr instead
33+
*/
2934
struct btrfs_block_group_cache *block_group;
35+
36+
/* key used to find this inode on disk. This is used by the code
37+
* to read in roots of subvolumes
38+
*/
3039
struct btrfs_key location;
40+
41+
/* the extent_tree has caches of all the extent mappings to disk */
3142
struct extent_map_tree extent_tree;
43+
44+
/* the io_tree does range state (DIRTY, LOCKED etc) */
3245
struct extent_io_tree io_tree;
46+
47+
/* special utility tree used to record which mirrors have already been
48+
* tried when checksums fail for a given block
49+
*/
3350
struct extent_io_tree io_failure_tree;
51+
52+
/* held while inserting checksums to avoid races */
3453
struct mutex csum_mutex;
54+
55+
/* held while inesrting or deleting extents from files */
3556
struct mutex extent_mutex;
57+
58+
/* held while logging the inode in tree-log.c */
3659
struct mutex log_mutex;
37-
struct inode vfs_inode;
60+
61+
/* used to order data wrt metadata */
3862
struct btrfs_ordered_inode_tree ordered_tree;
3963

64+
/* standard acl pointers */
4065
struct posix_acl *i_acl;
4166
struct posix_acl *i_default_acl;
4267

4368
/* for keeping track of orphaned inodes */
4469
struct list_head i_orphan;
4570

71+
/* list of all the delalloc inodes in the FS. There are times we need
72+
* to write all the delalloc pages to disk, and this list is used
73+
* to walk them all.
74+
*/
4675
struct list_head delalloc_inodes;
4776

48-
/* full 64 bit generation number */
77+
/* full 64 bit generation number, struct vfs_inode doesn't have a big
78+
* enough field for this.
79+
*/
4980
u64 generation;
5081

5182
/*
@@ -57,17 +88,34 @@ struct btrfs_inode {
5788
*/
5889
u64 logged_trans;
5990

60-
/* trans that last made a change that should be fully fsync'd */
91+
/*
92+
* trans that last made a change that should be fully fsync'd. This
93+
* gets reset to zero each time the inode is logged
94+
*/
6195
u64 log_dirty_trans;
96+
97+
/* total number of bytes pending delalloc, used by stat to calc the
98+
* real block usage of the file
99+
*/
62100
u64 delalloc_bytes;
101+
102+
/*
103+
* the size of the file stored in the metadata on disk. data=ordered
104+
* means the in-memory i_size might be larger than the size on disk
105+
* because not all the blocks are written yet.
106+
*/
63107
u64 disk_i_size;
108+
109+
/* flags field from the on disk inode */
64110
u32 flags;
65111

66112
/*
67113
* if this is a directory then index_cnt is the counter for the index
68114
* number for new files that are created
69115
*/
70116
u64 index_cnt;
117+
118+
struct inode vfs_inode;
71119
};
72120

73121
static inline struct btrfs_inode *BTRFS_I(struct inode *inode)

‎fs/btrfs/crc32c.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright (C) 2008 Oracle. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public
6+
* License v2 as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public
14+
* License along with this program; if not, write to the
15+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16+
* Boston, MA 021110-1307, USA.
17+
*/
18+
119
#ifndef __BTRFS_CRC32C__
220
#define __BTRFS_CRC32C__
321
#include <asm/byteorder.h>

0 commit comments

Comments
 (0)