2009-04-07 04:01:23 +02:00
|
|
|
/*
|
|
|
|
* the_nilfs.h - the_nilfs shared structure.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* Written by Ryusuke Konishi <ryusuke@osrg.net>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _THE_NILFS_H
|
|
|
|
#define _THE_NILFS_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2010-08-14 05:59:15 +02:00
|
|
|
#include <linux/rbtree.h>
|
2009-04-07 04:01:23 +02:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/backing-dev.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-04-07 04:01:23 +02:00
|
|
|
#include "sb.h"
|
|
|
|
|
|
|
|
/* the_nilfs struct */
|
|
|
|
enum {
|
|
|
|
THE_NILFS_INIT = 0, /* Information from super_block is set */
|
|
|
|
THE_NILFS_DISCONTINUED, /* 'next' pointer chain has broken */
|
2009-09-03 15:24:17 +02:00
|
|
|
THE_NILFS_GC_RUNNING, /* gc process is running */
|
2009-12-08 16:57:52 +01:00
|
|
|
THE_NILFS_SB_DIRTY, /* super block is dirty */
|
2009-04-07 04:01:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct the_nilfs - struct to supervise multiple nilfs mount points
|
|
|
|
* @ns_flags: flags
|
|
|
|
* @ns_bdev: block device
|
|
|
|
* @ns_sem: semaphore for shared states
|
2009-04-07 04:01:59 +02:00
|
|
|
* @ns_sbh: buffer heads of on-disk super blocks
|
|
|
|
* @ns_sbp: pointers to super block data
|
2010-06-28 10:49:33 +02:00
|
|
|
* @ns_sbwtime: previous write time of super block
|
|
|
|
* @ns_sbwcount: write count of super block
|
2009-04-07 04:01:59 +02:00
|
|
|
* @ns_sbsize: size of valid data in super block
|
2009-04-07 04:01:23 +02:00
|
|
|
* @ns_seg_seq: segment sequence counter
|
|
|
|
* @ns_segnum: index number of the latest full segment.
|
|
|
|
* @ns_nextnum: index number of the full segment index to be used next
|
|
|
|
* @ns_pseg_offset: offset of next partial segment in the current full segment
|
|
|
|
* @ns_cno: next checkpoint number
|
|
|
|
* @ns_ctime: write time of the last segment
|
|
|
|
* @ns_nongc_ctime: write time of the last segment not for cleaner operation
|
|
|
|
* @ns_ndirtyblks: Number of dirty data blocks
|
|
|
|
* @ns_last_segment_lock: lock protecting fields for the latest segment
|
|
|
|
* @ns_last_pseg: start block number of the latest segment
|
|
|
|
* @ns_last_seq: sequence value of the latest segment
|
|
|
|
* @ns_last_cno: checkpoint number of the latest segment
|
2009-04-07 04:01:54 +02:00
|
|
|
* @ns_prot_seq: least sequence number of segments which must not be reclaimed
|
2010-06-29 07:42:13 +02:00
|
|
|
* @ns_prev_seq: base sequence number used to decide if advance log cursor
|
2009-04-07 04:01:23 +02:00
|
|
|
* @ns_segctor_sem: segment constructor semaphore
|
|
|
|
* @ns_dat: DAT file inode
|
|
|
|
* @ns_cpfile: checkpoint file inode
|
|
|
|
* @ns_sufile: segusage file inode
|
2010-08-14 05:59:15 +02:00
|
|
|
* @ns_cptree: rb-tree of all mounted checkpoints (nilfs_root)
|
|
|
|
* @ns_cptree_lock: lock protecting @ns_cptree
|
2009-04-07 04:01:23 +02:00
|
|
|
* @ns_gc_inodes: dummy inodes to keep live blocks
|
2011-03-09 03:05:07 +01:00
|
|
|
* @ns_mount_opt: mount options
|
2009-04-07 04:01:23 +02:00
|
|
|
* @ns_blocksize_bits: bit length of block size
|
2010-05-22 17:17:48 +02:00
|
|
|
* @ns_blocksize: block size
|
2009-04-07 04:01:23 +02:00
|
|
|
* @ns_nsegments: number of segments in filesystem
|
|
|
|
* @ns_blocks_per_segment: number of blocks per segment
|
|
|
|
* @ns_r_segments_percentage: reserved segments percentage
|
|
|
|
* @ns_nrsvsegs: number of reserved segments
|
|
|
|
* @ns_first_data_block: block number of first data block
|
|
|
|
* @ns_inode_size: size of on-disk inode
|
|
|
|
* @ns_first_ino: first not-special inode number
|
|
|
|
* @ns_crc_seed: seed value of CRC32 calculation
|
|
|
|
*/
|
|
|
|
struct the_nilfs {
|
|
|
|
unsigned long ns_flags;
|
|
|
|
|
|
|
|
struct block_device *ns_bdev;
|
|
|
|
struct rw_semaphore ns_sem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* used for
|
|
|
|
* - loading the latest checkpoint exclusively.
|
|
|
|
* - allocating a new full segment.
|
|
|
|
* - protecting s_dirt in the super_block struct
|
|
|
|
* (see nilfs_write_super) and the following fields.
|
|
|
|
*/
|
2009-04-07 04:01:59 +02:00
|
|
|
struct buffer_head *ns_sbh[2];
|
|
|
|
struct nilfs_super_block *ns_sbp[2];
|
2010-06-28 10:49:33 +02:00
|
|
|
time_t ns_sbwtime;
|
|
|
|
unsigned ns_sbwcount;
|
2009-04-07 04:01:59 +02:00
|
|
|
unsigned ns_sbsize;
|
2009-04-07 04:01:23 +02:00
|
|
|
unsigned ns_mount_state;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following fields are dedicated to a writable FS-instance.
|
|
|
|
* Except for the period seeking checkpoint, code outside the segment
|
2009-04-07 04:01:45 +02:00
|
|
|
* constructor must lock a segment semaphore while accessing these
|
|
|
|
* fields.
|
2009-04-07 04:01:23 +02:00
|
|
|
* The writable FS-instance is sole during a lifetime of the_nilfs.
|
|
|
|
*/
|
|
|
|
u64 ns_seg_seq;
|
|
|
|
__u64 ns_segnum;
|
|
|
|
__u64 ns_nextnum;
|
|
|
|
unsigned long ns_pseg_offset;
|
|
|
|
__u64 ns_cno;
|
|
|
|
time_t ns_ctime;
|
|
|
|
time_t ns_nongc_ctime;
|
|
|
|
atomic_t ns_ndirtyblks;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following fields hold information on the latest partial segment
|
|
|
|
* written to disk with a super root. These fields are protected by
|
|
|
|
* ns_last_segment_lock.
|
|
|
|
*/
|
|
|
|
spinlock_t ns_last_segment_lock;
|
|
|
|
sector_t ns_last_pseg;
|
|
|
|
u64 ns_last_seq;
|
|
|
|
__u64 ns_last_cno;
|
2009-04-07 04:01:54 +02:00
|
|
|
u64 ns_prot_seq;
|
2010-06-29 07:42:13 +02:00
|
|
|
u64 ns_prev_seq;
|
2009-04-07 04:01:23 +02:00
|
|
|
|
|
|
|
struct rw_semaphore ns_segctor_sem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following fields are lock free except for the period before
|
|
|
|
* the_nilfs is initialized.
|
|
|
|
*/
|
|
|
|
struct inode *ns_dat;
|
|
|
|
struct inode *ns_cpfile;
|
|
|
|
struct inode *ns_sufile;
|
|
|
|
|
2010-08-14 05:59:15 +02:00
|
|
|
/* Checkpoint tree */
|
|
|
|
struct rb_root ns_cptree;
|
|
|
|
spinlock_t ns_cptree_lock;
|
|
|
|
|
2010-08-20 12:06:11 +02:00
|
|
|
/* GC inode list */
|
2009-04-07 04:01:23 +02:00
|
|
|
struct list_head ns_gc_inodes;
|
|
|
|
|
2011-03-09 03:05:07 +01:00
|
|
|
/* Mount options */
|
|
|
|
unsigned long ns_mount_opt;
|
|
|
|
|
2009-04-07 04:01:23 +02:00
|
|
|
/* Disk layout information (static) */
|
|
|
|
unsigned int ns_blocksize_bits;
|
2010-05-22 17:17:48 +02:00
|
|
|
unsigned int ns_blocksize;
|
2009-04-07 04:01:23 +02:00
|
|
|
unsigned long ns_nsegments;
|
|
|
|
unsigned long ns_blocks_per_segment;
|
|
|
|
unsigned long ns_r_segments_percentage;
|
|
|
|
unsigned long ns_nrsvsegs;
|
|
|
|
unsigned long ns_first_data_block;
|
|
|
|
int ns_inode_size;
|
|
|
|
int ns_first_ino;
|
|
|
|
u32 ns_crc_seed;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define THE_NILFS_FNS(bit, name) \
|
|
|
|
static inline void set_nilfs_##name(struct the_nilfs *nilfs) \
|
|
|
|
{ \
|
|
|
|
set_bit(THE_NILFS_##bit, &(nilfs)->ns_flags); \
|
|
|
|
} \
|
|
|
|
static inline void clear_nilfs_##name(struct the_nilfs *nilfs) \
|
|
|
|
{ \
|
|
|
|
clear_bit(THE_NILFS_##bit, &(nilfs)->ns_flags); \
|
|
|
|
} \
|
|
|
|
static inline int nilfs_##name(struct the_nilfs *nilfs) \
|
|
|
|
{ \
|
|
|
|
return test_bit(THE_NILFS_##bit, &(nilfs)->ns_flags); \
|
|
|
|
}
|
|
|
|
|
|
|
|
THE_NILFS_FNS(INIT, init)
|
|
|
|
THE_NILFS_FNS(DISCONTINUED, discontinued)
|
2009-09-03 15:24:17 +02:00
|
|
|
THE_NILFS_FNS(GC_RUNNING, gc_running)
|
2009-12-08 16:57:52 +01:00
|
|
|
THE_NILFS_FNS(SB_DIRTY, sb_dirty)
|
2009-04-07 04:01:23 +02:00
|
|
|
|
2011-03-09 03:05:07 +01:00
|
|
|
/*
|
|
|
|
* Mount option operations
|
|
|
|
*/
|
|
|
|
#define nilfs_clear_opt(nilfs, opt) \
|
|
|
|
do { (nilfs)->ns_mount_opt &= ~NILFS_MOUNT_##opt; } while (0)
|
|
|
|
#define nilfs_set_opt(nilfs, opt) \
|
|
|
|
do { (nilfs)->ns_mount_opt |= NILFS_MOUNT_##opt; } while (0)
|
|
|
|
#define nilfs_test_opt(nilfs, opt) ((nilfs)->ns_mount_opt & NILFS_MOUNT_##opt)
|
|
|
|
#define nilfs_write_opt(nilfs, mask, opt) \
|
|
|
|
do { (nilfs)->ns_mount_opt = \
|
|
|
|
(((nilfs)->ns_mount_opt & ~NILFS_MOUNT_##mask) | \
|
|
|
|
NILFS_MOUNT_##opt); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-08-14 05:59:15 +02:00
|
|
|
/**
|
|
|
|
* struct nilfs_root - nilfs root object
|
|
|
|
* @cno: checkpoint number
|
|
|
|
* @rb_node: red-black tree node
|
|
|
|
* @count: refcount of this structure
|
|
|
|
* @nilfs: nilfs object
|
|
|
|
* @ifile: inode file
|
|
|
|
* @root: root inode
|
|
|
|
* @inodes_count: number of inodes
|
|
|
|
* @blocks_count: number of blocks (Reserved)
|
|
|
|
*/
|
|
|
|
struct nilfs_root {
|
|
|
|
__u64 cno;
|
|
|
|
struct rb_node rb_node;
|
|
|
|
|
|
|
|
atomic_t count;
|
|
|
|
struct the_nilfs *nilfs;
|
|
|
|
struct inode *ifile;
|
|
|
|
|
|
|
|
atomic_t inodes_count;
|
|
|
|
atomic_t blocks_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Special checkpoint number */
|
|
|
|
#define NILFS_CPTREE_CURRENT_CNO 0
|
|
|
|
|
2009-04-07 04:01:59 +02:00
|
|
|
/* Minimum interval of periodical update of superblocks (in seconds) */
|
|
|
|
#define NILFS_SB_FREQ 10
|
|
|
|
|
2009-07-22 18:26:34 +02:00
|
|
|
static inline int nilfs_sb_need_update(struct the_nilfs *nilfs)
|
|
|
|
{
|
|
|
|
u64 t = get_seconds();
|
2010-06-28 10:49:33 +02:00
|
|
|
return t < nilfs->ns_sbwtime || t > nilfs->ns_sbwtime + NILFS_SB_FREQ;
|
2009-07-22 18:26:34 +02:00
|
|
|
}
|
|
|
|
|
2010-06-28 10:49:33 +02:00
|
|
|
static inline int nilfs_sb_will_flip(struct the_nilfs *nilfs)
|
2009-07-22 18:26:34 +02:00
|
|
|
{
|
2010-06-28 10:49:33 +02:00
|
|
|
int flip_bits = nilfs->ns_sbwcount & 0x0FL;
|
|
|
|
return (flip_bits != 0x08 && flip_bits != 0x0F);
|
2009-07-22 18:26:34 +02:00
|
|
|
}
|
|
|
|
|
2009-04-07 04:01:23 +02:00
|
|
|
void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64);
|
2010-09-08 19:07:56 +02:00
|
|
|
struct the_nilfs *alloc_nilfs(struct block_device *bdev);
|
|
|
|
void destroy_nilfs(struct the_nilfs *nilfs);
|
2009-04-07 04:01:23 +02:00
|
|
|
int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *);
|
|
|
|
int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *);
|
2010-01-30 10:06:35 +01:00
|
|
|
int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t);
|
2009-04-07 04:01:23 +02:00
|
|
|
int nilfs_count_free_blocks(struct the_nilfs *, sector_t *);
|
2010-08-14 05:59:15 +02:00
|
|
|
struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno);
|
|
|
|
struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs,
|
|
|
|
__u64 cno);
|
|
|
|
void nilfs_put_root(struct nilfs_root *root);
|
2009-06-07 18:39:31 +02:00
|
|
|
struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64);
|
2009-04-07 04:01:23 +02:00
|
|
|
int nilfs_near_disk_full(struct the_nilfs *);
|
2009-04-07 04:01:59 +02:00
|
|
|
void nilfs_fall_back_super_block(struct the_nilfs *);
|
|
|
|
void nilfs_swap_super_block(struct the_nilfs *);
|
2009-04-07 04:01:23 +02:00
|
|
|
|
|
|
|
|
2010-08-14 05:59:15 +02:00
|
|
|
static inline void nilfs_get_root(struct nilfs_root *root)
|
|
|
|
{
|
|
|
|
atomic_inc(&root->count);
|
|
|
|
}
|
|
|
|
|
2009-11-19 11:58:46 +01:00
|
|
|
static inline int nilfs_valid_fs(struct the_nilfs *nilfs)
|
|
|
|
{
|
|
|
|
unsigned valid_fs;
|
|
|
|
|
|
|
|
down_read(&nilfs->ns_sem);
|
|
|
|
valid_fs = (nilfs->ns_mount_state & NILFS_VALID_FS);
|
|
|
|
up_read(&nilfs->ns_sem);
|
|
|
|
return valid_fs;
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:01:23 +02:00
|
|
|
static inline void
|
|
|
|
nilfs_get_segment_range(struct the_nilfs *nilfs, __u64 segnum,
|
|
|
|
sector_t *seg_start, sector_t *seg_end)
|
|
|
|
{
|
|
|
|
*seg_start = (sector_t)nilfs->ns_blocks_per_segment * segnum;
|
|
|
|
*seg_end = *seg_start + nilfs->ns_blocks_per_segment - 1;
|
|
|
|
if (segnum == 0)
|
|
|
|
*seg_start = nilfs->ns_first_data_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline sector_t
|
|
|
|
nilfs_get_segment_start_blocknr(struct the_nilfs *nilfs, __u64 segnum)
|
|
|
|
{
|
|
|
|
return (segnum == 0) ? nilfs->ns_first_data_block :
|
|
|
|
(sector_t)nilfs->ns_blocks_per_segment * segnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __u64
|
|
|
|
nilfs_get_segnum_of_block(struct the_nilfs *nilfs, sector_t blocknr)
|
|
|
|
{
|
|
|
|
sector_t segnum = blocknr;
|
|
|
|
|
|
|
|
sector_div(segnum, nilfs->ns_blocks_per_segment);
|
|
|
|
return segnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
nilfs_terminate_segment(struct the_nilfs *nilfs, sector_t seg_start,
|
|
|
|
sector_t seg_end)
|
|
|
|
{
|
|
|
|
/* terminate the current full segment (used in case of I/O-error) */
|
|
|
|
nilfs->ns_pseg_offset = seg_end - seg_start + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void nilfs_shift_to_next_segment(struct the_nilfs *nilfs)
|
|
|
|
{
|
|
|
|
/* move forward with a full segment */
|
|
|
|
nilfs->ns_segnum = nilfs->ns_nextnum;
|
|
|
|
nilfs->ns_pseg_offset = 0;
|
|
|
|
nilfs->ns_seg_seq++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline __u64 nilfs_last_cno(struct the_nilfs *nilfs)
|
|
|
|
{
|
|
|
|
__u64 cno;
|
|
|
|
|
|
|
|
spin_lock(&nilfs->ns_last_segment_lock);
|
|
|
|
cno = nilfs->ns_last_cno;
|
|
|
|
spin_unlock(&nilfs->ns_last_segment_lock);
|
|
|
|
return cno;
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:01:58 +02:00
|
|
|
static inline int nilfs_segment_is_active(struct the_nilfs *nilfs, __u64 n)
|
|
|
|
{
|
|
|
|
return n == nilfs->ns_segnum || n == nilfs->ns_nextnum;
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:01:23 +02:00
|
|
|
#endif /* _THE_NILFS_H */
|