Commit 397b24a5 authored by mincheol's avatar mincheol
Browse files

memory free added

parent 847b6bed
......@@ -30,6 +30,11 @@ long extractmd_write_file(char *, char *, unsigned long);
long extractmd_write_file_per_group(char *, char *, unsigned long, int);
long extractmd_append_file(char *, char *, unsigned long);
static int extractmd_jread(struct buffer_head **, journal_t *, unsigned int);
int extractmd_journal_bmap(journal_t *, unsigned int, unsigned int *);
static int extractmd_do_readahead(journal_t *, unsigned int);
static void extractmd_journal_brelse_array(struct buffer_head *b[], int);
#define DEVICE_NAME "extractmd" /* Dev name as it appears in /proc/devices */
#define MAJOR_NUM 199 /* Device MAJOR number */
......@@ -126,6 +131,7 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
bh_redundant_sb2 = __bread(bdev, extractmd_group_first_block_no(sb, sbi->s_es->s_backup_bgs[1]), EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_super_block, bh_redundant_sb1->b_data, EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_super_block, bh_redundant_sb2->b_data, EXT4_BLOCK_SIZE(sb));
}
/* sparse super block? Yes -> then sb in group 0 or a power of 3, 5, or 7 */
......@@ -190,6 +196,8 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
memcpy(buffer_inode_table + EXT4_BLOCK_SIZE(sb) * h, bh_inode_table->b_data, EXT4_BLOCK_SIZE(sb));
}
extractmd_write_file_per_group(path_inode_table , buffer_inode_table, EXT4_BLOCK_SIZE(sb) * nr_inode_table_block, i);
kfree(buffer_inode_table);
}
/* reserved GDT, if not flexible block group, extract reserved GDT
......@@ -206,8 +214,11 @@ static int extractmd_ioctl(struct inode *inode, struct file *f, struct extractmd
/* journal */
for(j = 0; j < nr_journal_blocks; j++)
{
bh_journal = __bread(sbi->s_journal->j_dev, j, EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_journal, bh_journal->b_data, EXT4_BLOCK_SIZE(sb));
if(extractmd_jread(&bh_journal, sbi->s_journal, j) == 0)
{
bh_journal = __bread(sbi->s_journal->j_dev, j, EXT4_BLOCK_SIZE(sb));
extractmd_append_file(path_journal, bh_journal->b_data, EXT4_BLOCK_SIZE(sb));
}
}
filp_close(fp, NULL);
......@@ -334,6 +345,139 @@ long extractmd_append_file(char *path, char* data, unsigned long size)
return ret;
}
static int extractmd_jread(struct buffer_head **bhp, journal_t *journal, unsigned int offset)
{
int err;
unsigned int blocknr;
struct buffer_head *bh;
*bhp = NULL;
if (offset >= journal->j_maxlen) {
printk(KERN_ERR "JBD: corrupted journal superblock\n");
return -EIO;
}
err = extractmd_journal_bmap(journal, offset, &blocknr);
if (err) {
printk (KERN_ERR "JBD: bad block at offset %u\n",
offset);
return err;
}
bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
if (!bh)
return -ENOMEM;
if (!buffer_uptodate(bh)) {
/* If this is a brand new buffer, start readahead.
Otherwise, we assume we are already reading it. */
if (!buffer_req(bh))
extractmd_do_readahead(journal, offset);
wait_on_buffer(bh);
}
if (!buffer_uptodate(bh)) {
printk (KERN_ERR "JBD: Failed to read block at offset %u\n",
offset);
brelse(bh);
return -EIO;
}
*bhp = bh;
return 0;
}
int extractmd_journal_bmap(journal_t *journal, unsigned int blocknr, unsigned int *retp)
{
int err = 0;
unsigned int ret;
if (journal->j_inode) {
ret = bmap(journal->j_inode, blocknr);
if (ret)
*retp = ret;
else {
char b[BDEVNAME_SIZE];
printk(KERN_ALERT "%s: journal block not found "
"at offset %u on %s\n",
__func__,
blocknr,
bdevname(journal->j_dev, b));
err = -EIO;
//__journal_abort_soft(journal, err);
}
} else {
*retp = blocknr; /* +journal->j_blk_offset */
}
return err;
}
#define MAXBUF 8
static int extractmd_do_readahead(journal_t *journal, unsigned int start)
{
int err;
unsigned int max, nbufs, next;
unsigned int blocknr;
struct buffer_head *bh;
struct buffer_head * bufs[MAXBUF];
/* Do up to 128K of readahead */
max = start + (128 * 1024 / journal->j_blocksize);
if (max > journal->j_maxlen)
max = journal->j_maxlen;
/* Do the readahead itself. We'll submit MAXBUF buffer_heads at
* a time to the block device IO layer. */
nbufs = 0;
for (next = start; next < max; next++) {
err = extractmd_journal_bmap(journal, next, &blocknr);
if (err) {
printk (KERN_ERR "JBD: bad block at offset %u\n",
next);
goto failed;
}
bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
if (!bh) {
err = -ENOMEM;
goto failed;
}
if (!buffer_uptodate(bh) && !buffer_locked(bh)) {
bufs[nbufs++] = bh;
if (nbufs == MAXBUF) {
ll_rw_block(READ, nbufs, bufs);
extractmd_journal_brelse_array(bufs, nbufs);
nbufs = 0;
}
} else
brelse(bh);
}
if (nbufs)
ll_rw_block(READ, nbufs, bufs);
err = 0;
failed:
if (nbufs)
extractmd_journal_brelse_array(bufs, nbufs);
return err;
}
static void extractmd_journal_brelse_array(struct buffer_head *b[], int n)
{
while (--n >= 0)
brelse (b[n]);
}
module_init(init_extractmd);
module_exit(cleanup_extractmd);
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment