From bf4703471199baca3a80e7dbbf3755606817a21f Mon Sep 17 00:00:00 2001 From: mmex Date: Mon, 14 Jul 2003 22:22:22 +0000 Subject: [PATCH] - cleanup come of the configuration files to be more compatible and define some new things to help building rpms. --- lustre/include/linux/lustre_fsfilt.h | 15 ++++++++ lustre/obdclass/fsfilt_ext3.c | 74 ++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/lustre/include/linux/lustre_fsfilt.h b/lustre/include/linux/lustre_fsfilt.h index 4523af7..17d5f76 100644 --- a/lustre/include/linux/lustre_fsfilt.h +++ b/lustre/include/linux/lustre_fsfilt.h @@ -61,6 +61,8 @@ struct fsfilt_operations { int (* fs_sync)(struct super_block *sb); int (* fs_prep_san_write)(struct inode *inode, long *blocks, int nblocks, loff_t newsize); + int (* fs_write_record)(struct file *, char *, loff_t, loff_t *); + int (* fs_read_record)(struct file *, char *, loff_t, loff_t *); }; extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops); @@ -202,6 +204,19 @@ static inline int fs_prep_san_write(struct obd_device *obd, return obd->obd_fsops->fs_prep_san_write(inode, blocks, nblocks, newsize); } + +static inline int fsfilt_read_record(struct obd_device *obd, struct file *file, + char *buf, loff_t size, loff_t *offs) +{ + return obd->obd_fsops->fs_read_record(file, buf, size, offs); +} + +static inline int fsfilt_write_record(struct obd_device *obd, struct file *file, + char *buf, loff_t size, loff_t *offs) +{ + return obd->obd_fsops->fs_write_record(file, buf, size, offs); +} + #endif /* __KERNEL__ */ #endif diff --git a/lustre/obdclass/fsfilt_ext3.c b/lustre/obdclass/fsfilt_ext3.c index a3b295f..bff78a1 100644 --- a/lustre/obdclass/fsfilt_ext3.c +++ b/lustre/obdclass/fsfilt_ext3.c @@ -501,6 +501,78 @@ static int fsfilt_ext3_prep_san_write(struct inode *inode, long *blocks, return ext3_prep_san_write(inode, blocks, nblocks, newsize); } +static int fsfilt_ext3_read_record(struct file * file, char * buf, + loff_t size, loff_t *offs) +{ + struct buffer_head *bh; + unsigned long block, boffs; + struct inode *inode = file->f_dentry->d_inode; + int err; + + if (inode->i_size < *offs + size) + return -EIO; + + block = *offs >> inode->i_blkbits; + bh = ext3_bread(NULL, inode, block, 0, &err); + if (!bh) + return err; + + boffs = (unsigned) *offs / bh->b_size; + if (boffs + size > bh->b_size) { + brelse(bh); + return -EIO; + } + + memcpy(buf, bh->b_data + boffs, size); + brelse(bh); + *offs += size; + return size; +} + +static int fsfilt_ext3_write_record(struct file * file, char * buf, + loff_t size, loff_t *offs) +{ + struct buffer_head *bh; + unsigned long block, boffs; + struct inode *inode = file->f_dentry->d_inode; + handle_t *handle; + int err; + + handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS + 2); + if (!handle) + return -EIO; + + block = *offs >> inode->i_blkbits; + if (block > inode->i_size >> inode->i_blkbits) { + down(&inode->i_sem); + inode->i_size = block << inode->i_blkbits; + up(&inode->i_sem); + } + bh = ext3_bread(handle, inode, block, 1, &err); + if (!bh) + goto out; + + boffs = (unsigned) *offs / bh->b_size; + if (boffs + size > bh->b_size) + goto out; + + err = ext3_journal_get_write_access(handle, bh); + if (err) + goto out; + memcpy(bh->b_data + boffs, buf, size); + err = ext3_journal_dirty_metadata(handle, bh); + if (err) + goto out; + err = size; +out: + if (bh) + brelse(bh); + ext3_journal_stop(handle, inode); + if (err > 0) + *offs += size; + return err; +} + static struct fsfilt_operations fsfilt_ext3_ops = { fs_type: "ext3", fs_owner: THIS_MODULE, @@ -516,6 +588,8 @@ static struct fsfilt_operations fsfilt_ext3_ops = { fs_statfs: fsfilt_ext3_statfs, fs_sync: fsfilt_ext3_sync, fs_prep_san_write: fsfilt_ext3_prep_san_write, + fs_write_record: fsfilt_ext3_write_record, + fs_read_record: fsfilt_ext3_read_record, }; static int __init fsfilt_ext3_init(void) -- 1.8.3.1