fix hang of remote logfile update

appending to logfile did not update copy_end_pos, so the copy
brick never switched off.
This commit is contained in:
Thomas Schoebel-Theuer 2012-01-25 14:20:47 +01:00 committed by Thomas Schoebel-Theuer
parent 81bfb9471a
commit 58f6981806
2 changed files with 44 additions and 42 deletions

View File

@ -674,8 +674,11 @@ static int aio_submit_thread(void *data)
struct aio_threadinfo *tinfo = data;
struct aio_output *output = tinfo->output;
struct file *file = output->filp;
int err;
mm_segment_t oldfs;
int err = -EINVAL;
CHECK_PTR_NULL(file, done);
/* TODO: this is provisionary. We only need it for sys_io_submit()
* which uses userspace concepts like file handles.
* This should be accompanied by a future kernelsapce vfs_submit() or
@ -687,7 +690,7 @@ static int aio_submit_thread(void *data)
if (unlikely(err < 0))
goto done;
output->fd = err;
fd_install(err, output->filp);
fd_install(err, file);
MARS_INF("kthread has started.\n");
//set_user_nice(current, -20);
@ -696,28 +699,18 @@ static int aio_submit_thread(void *data)
err = -ENOMEM;
if (unlikely(!current->mm))
goto done;
#if 1
if (true) {
mm_segment_t oldfs;
if (!current->mm) {
MARS_ERR("mm = %p\n", current->mm);
err = -EINVAL;
goto done;
}
oldfs = get_fs();
set_fs(get_ds());
err = sys_io_setup(MARS_MAX_AIO, &output->ctxp);
set_fs(oldfs);
if (unlikely(err < 0))
goto done;
}
#endif
goto cleanup_fd;
oldfs = get_fs();
set_fs(get_ds());
err = sys_io_setup(MARS_MAX_AIO, &output->ctxp);
set_fs(oldfs);
if (unlikely(err < 0))
goto cleanup_mm;
err = aio_start_thread(output, 1, aio_event_thread);
if (unlikely(err < 0))
goto done;
goto cleanup_ctxp;
while (!kthread_should_stop()) {
struct aio_mref_aspect *mref_a;
@ -802,24 +795,26 @@ static int aio_submit_thread(void *data)
aio_stop_thread(output, 1, true);
#if 1
if (true) {
mm_segment_t oldfs;
MARS_INF("destroying ioctx.....\n");
oldfs = get_fs();
set_fs(get_ds());
sys_io_destroy(output->ctxp);
set_fs(oldfs);
output->ctxp = 0;
}
#endif
MARS_INF("destroying fd %d\n", output->fd);
cleanup_ctxp:
MARS_DBG("destroying ioctx.....\n");
oldfs = get_fs();
set_fs(get_ds());
sys_io_destroy(output->ctxp);
set_fs(oldfs);
output->ctxp = 0;
cleanup_mm:
unuse_fake_mm();
cleanup_fd:
MARS_DBG("destroying fd %d\n", output->fd);
fd_uninstall(output->fd);
put_unused_fd(output->fd);
unuse_fake_mm();
err = 0;
done:
MARS_DBG("status = %d\n", err);
tinfo->terminated = true;
wake_up_interruptible_all(&tinfo->event);
return err;
@ -925,7 +920,7 @@ static int aio_switch(struct aio_brick *brick)
if (!brick->power.button)
goto cleanup;
if (brick->power.led_on)
if (brick->power.led_on || output->filp)
goto done;
mars_power_led_off((void*)brick, false);
@ -940,13 +935,16 @@ static int aio_switch(struct aio_brick *brick)
output->filp = filp_open(path, flags, prot);
set_fs(oldfs);
if (unlikely(IS_ERR(output->filp))) {
MARS_DBG("opened file '%s' flags = %d prot = %d filp = %p\n", path, flags, prot, output->filp);
if (unlikely(!output->filp || IS_ERR(output->filp))) {
err = PTR_ERR(output->filp);
MARS_ERR("can't open file '%s' status=%d\n", path, err);
output->filp = NULL;
if (err >= 0)
err = -ENOENT;
return err;
}
MARS_DBG("opened file '%s'\n", path);
#if 1
{
struct inode *inode = output->filp->f_mapping->host;

View File

@ -758,14 +758,15 @@ bool _is_peer_logfile(const char *name, const char *id)
}
static
int _update_file(struct mars_global *global, const char *switch_path, const char *copy_path, const char *file, const char *peer, loff_t end_pos)
int _update_file(struct mars_rotate *rot, const char *switch_path, const char *copy_path, const char *file, const char *peer, loff_t end_pos)
{
struct mars_global *global = rot->global;
const char *tmp = path_make("%s@%s", file, peer);
const char *argv[2] = { tmp, file };
struct copy_brick *copy = NULL;
int status = -ENOMEM;
if (unlikely(!tmp))
if (unlikely(!tmp || !global))
goto done;
MARS_DBG("src = '%s' dst = '%s'\n", tmp, file);
@ -774,6 +775,7 @@ int _update_file(struct mars_global *global, const char *switch_path, const char
if (end_pos > copy->copy_end) {
MARS_DBG("appending to '%s' %lld => %lld\n", copy_path, copy->copy_end, end_pos);
copy->copy_end = end_pos;
rot->copy_end_pos = end_pos;
}
}
@ -820,7 +822,9 @@ int check_logfile(struct mars_peerinfo *peer, struct mars_dent *remote_dent, str
bool copy_is_done = (is_my_copy && copy_brick->copy_last == copy_brick->copy_end && local_dent != NULL && copy_brick->copy_end == rot->copy_end_pos);
bool is_next_copy = (remote_dent->d_serial == parent->d_logfile_serial + 1);
MARS_DBG("current copy brick '%s' copy_last = %lld copy_end = %lld dent '%s' serial = %d/%d is_done = %d is_my_copy = %d is_next_copy = %d\n", copy_brick->brick_path, copy_brick->copy_last, copy_brick->copy_end, remote_dent->d_path, remote_dent->d_serial, parent->d_logfile_serial, copy_is_done, is_my_copy, is_next_copy);
MARS_DBG("current copy brick '%s' copy_last = %lld copy_end = %lld dent '%s' serial = %d/%d local_dent = '%s' copy_end_pos = %lld | is_done = %d is_my_copy = %d is_next_copy = %d\n",
copy_brick->brick_path, copy_brick->copy_last, copy_brick->copy_end, remote_dent->d_path, remote_dent->d_serial, parent->d_logfile_serial, local_dent ? local_dent->d_path : "", rot->copy_end_pos,
copy_is_done, is_my_copy, is_next_copy);
if (is_my_copy) {
rot->copy_is_done = copy_is_done;
@ -857,7 +861,7 @@ treat:
// start / treat copy brick instance
rot->copy_end_pos = src_size;
status = _update_file(peer->global, switch_path, copy_path, remote_dent->d_path, peer->peer, src_size);
status = _update_file(rot, switch_path, copy_path, remote_dent->d_path, peer->peer, src_size);
MARS_DBG("update '%s' from peer '%s' status = %d\n", remote_dent->d_path, peer->peer, status);
if (status < 0) {
goto done;