From bba4bb20f13c2add0a12f9f939e5b361e9f6942b Mon Sep 17 00:00:00 2001 From: jxiong Date: Tue, 2 Dec 2008 01:57:13 +0000 Subject: [PATCH] b=16074 r=oleg,jay small fixes for liblustre. --- lustre/liblustre/llite_cl.c | 40 ++++++++++++++-------------------------- lustre/liblustre/rw.c | 3 +-- lustre/liblustre/tests/sanity.c | 2 +- lustre/osc/osc_io.c | 20 ++++++++------------ lustre/ptlrpc/ptlrpcd.c | 21 ++++++++++++--------- 5 files changed, 36 insertions(+), 50 deletions(-) diff --git a/lustre/liblustre/llite_cl.c b/lustre/liblustre/llite_cl.c index ed19dd3..e3c340e 100644 --- a/lustre/liblustre/llite_cl.c +++ b/lustre/liblustre/llite_cl.c @@ -278,10 +278,6 @@ static int slp_io_init(const struct lu_env *env, struct cl_object *obj, /* "If nbyte is 0, read() will return 0 and have no other * results." -- Single Unix Spec */ if (count == 0) - return 1; - /* "If nbyte is 0, read() will return 0 and have no other - * results." -- Single Unix Spec */ - if (count == 0) result = 1; else { vio->cui_tot_count = count; @@ -289,7 +285,7 @@ static int slp_io_init(const struct lu_env *env, struct cl_object *obj, } } - return 0; + return result; } static int slp_attr_get(const struct lu_env *env, struct cl_object *obj, @@ -431,38 +427,29 @@ static const struct cl_lock_operations slp_lock_ops = { * */ -static int slp_io_rw_lock(const struct lu_env *env, struct cl_io *io, - enum cl_lock_mode mode, loff_t start, loff_t end) -{ - int result; - - LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE); - - if (!io->u.ci_wr.wr_append) { // No lock without O_APPEND in liblustre - return 0; - } - - result = ccc_io_one_lock(env, io, 0, mode, start, end); - - return result; -} - -static int slp_io_write_lock(const struct lu_env *env, +static int slp_io_rw_lock(const struct lu_env *env, const struct cl_io_slice *ios) { struct cl_io *io = ios->cis_io; loff_t start; loff_t end; - if (io->u.ci_wr.wr_append) { + if (cl_io_is_append(io)) { start = 0; end = OBD_OBJECT_EOF; } else { start = io->u.ci_wr.wr.crw_pos; end = start + io->u.ci_wr.wr.crw_count - 1; } - - return slp_io_rw_lock(env, io, CLM_WRITE, start, end); + /* + * This acquires real DLM lock only in O_APPEND case, because of + * the io->ci_lockreq setting in llu_io_init(). + */ + LASSERT(ergo(cl_io_is_append(io), io->ci_lockreq == CILR_MANDATORY)); + LASSERT(ergo(!cl_io_is_append(io), io->ci_lockreq == CILR_NEVER)); + return ccc_io_one_lock(env, io, 0, + io->ci_type == CIT_READ ? CLM_READ : CLM_WRITE, + start, end); } @@ -749,12 +736,13 @@ static const struct cl_io_operations ccc_io_ops = { .op = { [CIT_READ] = { .cio_fini = ccc_io_fini, + .cio_lock = slp_io_rw_lock, .cio_start = slp_io_start, .cio_end = ccc_io_end }, [CIT_WRITE] = { .cio_fini = ccc_io_fini, - .cio_lock = slp_io_write_lock, + .cio_lock = slp_io_rw_lock, .cio_start = slp_io_start, .cio_end = ccc_io_end }, diff --git a/lustre/liblustre/rw.c b/lustre/liblustre/rw.c index 21d8e42..89f22d0 100644 --- a/lustre/liblustre/rw.c +++ b/lustre/liblustre/rw.c @@ -446,11 +446,10 @@ void llu_io_init(struct cl_io *io, struct inode *inode, int write) io->u.ci_wr.wr_append = lli->lli_open_flags & O_APPEND; io->ci_obj = llu_i2info(inode)->lli_clob; - if (lli->lli_open_flags & O_APPEND) + if ((lli->lli_open_flags & O_APPEND) && write) io->ci_lockreq = CILR_MANDATORY; else io->ci_lockreq = CILR_NEVER; - } int llu_iop_read(struct inode *ino, diff --git a/lustre/liblustre/tests/sanity.c b/lustre/liblustre/tests/sanity.c index 070e3c6..929fda6 100644 --- a/lustre/liblustre/tests/sanity.c +++ b/lustre/liblustre/tests/sanity.c @@ -734,7 +734,7 @@ int t22(char *name) ENTER("make sure O_APPEND take effect"); snprintf(file, MAX_PATH_LENGTH, "%s/test_t22_file", lustre_path); - fd = open(file, O_RDWR|O_CREAT|O_APPEND, (mode_t)0666); + fd = open(file, O_TRUNC|O_RDWR|O_CREAT|O_APPEND, (mode_t)0666); if (fd < 0) { printf("error open file: %s\n", strerror(errno)); return(-1); diff --git a/lustre/osc/osc_io.c b/lustre/osc/osc_io.c index 4b4ae0a..180e4f1 100644 --- a/lustre/osc/osc_io.c +++ b/lustre/osc/osc_io.c @@ -602,19 +602,15 @@ static void osc_req_attr_set(const struct lu_env *env, opg = osc_cl_page_osc(apage); apage = opg->ops_cl.cpl_page; /* now apage is a sub-page */ lock = cl_lock_at_page(env, apage->cp_obj, apage, NULL, 1, 1); - if (lock != NULL) { - olck = osc_lock_at(lock); - LASSERT(olck != NULL); - /* check for lockless io. */ - if (olck->ols_lock != NULL) { - oa->o_handle = olck->ols_lock->l_remote_handle; - oa->o_valid |= OBD_MD_FLHANDLE; - } - cl_lock_put(env, lock); - } else { - /* Should only be possible with liblustre */ - LASSERT(LIBLUSTRE_CLIENT); + LASSERT(lock != NULL); + olck = osc_lock_at(lock); + LASSERT(olck != NULL); + /* check for lockless io. */ + if (olck->ols_lock != NULL) { + oa->o_handle = olck->ols_lock->l_remote_handle; + oa->o_valid |= OBD_MD_FLHANDLE; } + cl_lock_put(env, lock); } } diff --git a/lustre/ptlrpc/ptlrpcd.c b/lustre/ptlrpc/ptlrpcd.c index a52e62b..867ec66 100644 --- a/lustre/ptlrpc/ptlrpcd.c +++ b/lustre/ptlrpc/ptlrpcd.c @@ -296,16 +296,19 @@ int ptlrpcd_check_async_rpcs(void *arg) pc->pc_recurred++; if (pc->pc_recurred == 1) { - lu_context_enter(&pc->pc_env.le_ctx); - rc = ptlrpcd_check(&pc->pc_env, pc); - lu_context_exit(&pc->pc_env.le_ctx); - if (!rc) - ptlrpc_expired_set(pc->pc_set); - /* - * XXX: send replay requests. - */ - if (test_bit(LIOD_RECOVERY, &pc->pc_flags)) + rc = lu_env_refill(&pc->pc_env); + if (rc == 0) { + lu_context_enter(&pc->pc_env.le_ctx); rc = ptlrpcd_check(&pc->pc_env, pc); + lu_context_exit(&pc->pc_env.le_ctx); + if (!rc) + ptlrpc_expired_set(pc->pc_set); + /* + * XXX: send replay requests. + */ + if (test_bit(LIOD_RECOVERY, &pc->pc_flags)) + rc = ptlrpcd_check(&pc->pc_env, pc); + } } pc->pc_recurred--; -- 1.8.3.1