sio: convert to new mapfree infrastructure

This commit is contained in:
Thomas Schoebel-Theuer 2015-07-14 13:53:11 +02:00
parent 6d8bd64b7a
commit 91f458fe66
2 changed files with 22 additions and 35 deletions

View File

@ -58,7 +58,7 @@ static int sio_ref_get(struct sio_output *output, struct mref_object *mref)
return mref->ref_len;
}
file = output->filp;
file = output->mf->mf_filp;
if (file) {
loff_t total_size = i_size_read(file->f_mapping->host);
mref->ref_total_size = total_size;
@ -117,10 +117,8 @@ static void sio_ref_put(struct sio_output *output, struct mref_object *mref)
if (!_mref_put(mref))
return;
file = output->filp;
if (file) {
file = output->mf->mf_filp;
mref->ref_total_size = i_size_read(file->f_mapping->host);
}
mref_a = sio_mref_get_aspect(output->brick, mref);
if (mref_a && mref_a->do_dealloc) {
@ -159,7 +157,7 @@ static int transfer_none(int cmd,
static
int write_aops(struct sio_output *output, struct mref_object *mref)
{
struct file *file = output->filp;
struct file *file = output->mf->mf_filp;
loff_t pos = mref->ref_pos;
void *data = mref->ref_data;
int len = mref->ref_len;
@ -296,7 +294,7 @@ int read_aops(struct sio_output *output, struct mref_object *mref)
oldfs = get_fs();
set_fs(get_ds());
ret = vfs_read(output->filp, mref->ref_data, len, &pos);
ret = vfs_read(output->mf->mf_filp, mref->ref_data, len, &pos);
set_fs(oldfs);
#else
struct cookie_data cookie = {
@ -311,7 +309,7 @@ int read_aops(struct sio_output *output, struct mref_object *mref)
.u.data = &cookie,
};
ret = splice_direct_to_actor(output->filp, &sd, sio_direct_splice_actor);
ret = splice_direct_to_actor(output->mf->mf_filp, &sd, sio_direct_splice_actor);
#endif
if (unlikely(ret < 0)) {
@ -322,7 +320,7 @@ int read_aops(struct sio_output *output, struct mref_object *mref)
static void sync_file(struct sio_output *output)
{
struct file *file = output->filp;
struct file *file = output->mf->mf_filp;
int ret;
#if defined(S_BIAS) || (defined(RHEL_MAJOR) && (RHEL_MAJOR < 7))
ret = vfs_fsync(file, file->f_path.dentry, 1);
@ -382,7 +380,7 @@ void _sio_ref_io(struct sio_threadinfo *tinfo, struct mref_object *mref)
atomic_inc(&tinfo->fly_count);
if (unlikely(!output->filp)) {
if (unlikely(!output->mf || !output->mf->mf_filp)) {
status = -EINVAL;
goto done;
}
@ -400,6 +398,7 @@ void _sio_ref_io(struct sio_threadinfo *tinfo, struct mref_object *mref)
sync_file(output);
}
mapfree_set(output->mf, mref->ref_pos, mref->ref_pos + mref->ref_len);
done:
_complete(output, mref, status);
@ -429,6 +428,8 @@ void sio_ref_io(struct sio_output *output, struct mref_object *mref)
atomic_inc(&mars_global_io_flying);
_mref_get(mref);
mapfree_set(output->mf, mref->ref_pos, -1);
index = 0;
if (mref->ref_rw == READ) {
traced_lock(&output->g_lock, flags);
@ -495,7 +496,7 @@ static int sio_thread(void *data)
static int sio_get_info(struct sio_output *output, struct mars_info *info)
{
struct file *file = output->filp;
struct file *file = output->mf->mf_filp;
if (unlikely(!file || !file->f_mapping || !file->f_mapping->host))
return -EINVAL;
@ -583,13 +584,10 @@ static int sio_switch(struct sio_brick *brick)
static int sio_nr = 0;
struct sio_output *output = brick->outputs[0];
const char *path = output->brick->brick_path;
int prot = 0600;
mm_segment_t oldfs;
int status = 0;
if (brick->power.button) {
int flags = O_CREAT | O_RDWR | O_LARGEFILE;
struct address_space *mapping;
int index;
if (brick->power.led_on)
@ -602,26 +600,13 @@ static int sio_switch(struct sio_brick *brick)
mars_power_led_off((void*)brick, false);
// TODO: convert to mapfree infrastructure
oldfs = get_fs();
set_fs(get_ds());
output->filp = filp_open(path, flags, prot);
set_fs(oldfs);
if (unlikely(IS_ERR(output->filp))) {
status = PTR_ERR(output->filp);
MARS_ERR("can't open file '%s' status=%d\n", path, status);
output->filp = NULL;
output->mf = mapfree_get(path, flags);
if (unlikely(IS_ERR(output->mf))) {
MARS_ERR("could not open file = '%s' flags = %d\n", path, flags);
status = -ENOENT;
goto done;
}
if ((mapping = output->filp->f_mapping)) {
mapping_set_gfp_mask(mapping, mapping_gfp_mask(mapping) & ~(__GFP_IO | __GFP_FS));
}
MARS_INF("opened file '%s' as %p\n", path, output->filp);
output->index = 0;
for (index = 0; index <= WITH_THREAD; index++) {
struct sio_threadinfo *tinfo = &output->tinfo[index];
@ -648,10 +633,10 @@ done:
brick_thread_stop(tinfo->thread);
tinfo->thread = NULL;
}
if (output->filp) {
if (output->mf) {
MARS_DBG("closing file\n");
filp_close(output->filp, NULL);
output->filp = NULL;
mapfree_put(output->mf);
output->mf = NULL;
}
mars_power_led_off((void*)brick, true);
}

View File

@ -24,6 +24,8 @@
#ifndef MARS_SIO_H
#define MARS_SIO_H
#include "lib_mapfree.h"
#define WITH_THREAD 16
struct sio_mref_aspect {
@ -59,7 +61,7 @@ struct sio_threadinfo {
struct sio_output {
MARS_OUTPUT(sio);
// private
struct file *filp;
struct mapfree_info *mf;
struct sio_threadinfo tinfo[WITH_THREAD+1];
spinlock_t g_lock;
int index;