From 422e5995808bee60407a78020825ab369e1449bd Mon Sep 17 00:00:00 2001 From: jxiong Date: Wed, 27 May 2009 02:40:46 +0000 Subject: [PATCH] b=18721 i=oleg,liang,rread liblustre fixed. --- libcfs/include/libcfs/user-lock.h | 2 +- libcfs/libcfs/user-lock.c | 15 +++++--- libcfs/libcfs/user-prim.c | 4 ++ lustre/include/lclient.h | 4 ++ lustre/lclient/lcommon_cl.c | 77 +++++++++++++++++++++++++++++++++++---- lustre/liblustre/llite_cl.c | 21 ++++++++--- lustre/liblustre/llite_lib.h | 6 +-- lustre/liblustre/rw.c | 35 ++++-------------- lustre/llite/vvp_io.c | 67 ++-------------------------------- 9 files changed, 114 insertions(+), 117 deletions(-) diff --git a/libcfs/include/libcfs/user-lock.h b/libcfs/include/libcfs/user-lock.h index 729f600..6d87c0d 100644 --- a/libcfs/include/libcfs/user-lock.h +++ b/libcfs/include/libcfs/user-lock.h @@ -149,8 +149,8 @@ struct completion { }; typedef int (*cfs_wait_handler_t) (int timeout); void init_completion_module(cfs_wait_handler_t handler); +int call_wait_handler(int timeout); void init_completion(struct completion *c); -void init_completion_module(cfs_wait_handler_t handler); void complete(struct completion *c); void wait_for_completion(struct completion *c); int wait_for_completion_interruptible(struct completion *c); diff --git a/libcfs/libcfs/user-lock.c b/libcfs/libcfs/user-lock.c index d36a17b..0a3471a 100644 --- a/libcfs/libcfs/user-lock.c +++ b/libcfs/libcfs/user-lock.c @@ -154,6 +154,13 @@ void init_completion_module(cfs_wait_handler_t handler) wait_handler = handler; } +int call_wait_handler(int timeout) +{ + if (!wait_handler) + return -ENOSYS; + return wait_handler(timeout); +} + void init_completion(struct completion *c) { LASSERT(c != NULL); @@ -172,9 +179,7 @@ void wait_for_completion(struct completion *c) { LASSERT(c != NULL); do { - if (wait_handler) - wait_handler(1000); - else + if (call_wait_handler(1000) < 0) break; } while (c->done == 0); } @@ -183,9 +188,7 @@ int wait_for_completion_interruptible(struct completion *c) { LASSERT(c != NULL); do { - if (wait_handler) - wait_handler(1000); - else + if (call_wait_handler(1000) < 0) break; } while (c->done == 0); return 0; diff --git a/libcfs/libcfs/user-prim.c b/libcfs/libcfs/user-prim.c index ee787e8..03e4bea 100644 --- a/libcfs/libcfs/user-prim.c +++ b/libcfs/libcfs/user-prim.c @@ -117,6 +117,9 @@ void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state) { LASSERT(link != NULL); (void)link; + + /* well, wait for something to happen */ + call_wait_handler(0); } int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, cfs_task_state_t state, @@ -124,6 +127,7 @@ int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, cfs_task_state_t state, { LASSERT(link != NULL); (void)link; + call_wait_handler(timeout); return 0; } diff --git a/lustre/include/lclient.h b/lustre/include/lclient.h index e1e18f7..2eb2425 100644 --- a/lustre/include/lclient.h +++ b/lustre/include/lclient.h @@ -328,6 +328,10 @@ int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io, __u32 enqflags, enum cl_lock_mode mode, loff_t start, loff_t end); void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios); +void ccc_io_advance(const struct lu_env *env, const struct cl_io_slice *ios, + size_t nob); +void ccc_io_update_iov(const struct lu_env *env, struct ccc_io *cio, + struct cl_io *io); int ccc_prep_size(const struct lu_env *env, struct cl_object *obj, struct cl_io *io, loff_t start, size_t count, int vfslock, int *exceed); diff --git a/lustre/lclient/lcommon_cl.c b/lustre/lclient/lcommon_cl.c index 53eda90..4fbf688 100644 --- a/lustre/lclient/lcommon_cl.c +++ b/lustre/lclient/lcommon_cl.c @@ -465,7 +465,7 @@ int ccc_page_is_under_lock(const struct lu_env *env, const struct cl_page_slice *slice, struct cl_io *io) { - struct ccc_io *vio = ccc_env_io(env); + struct ccc_io *cio = ccc_env_io(env); struct cl_lock_descr *desc = &ccc_env_info(env)->cti_descr; struct cl_page *page = slice->cpl_page; @@ -475,7 +475,7 @@ int ccc_page_is_under_lock(const struct lu_env *env, if (io->ci_type == CIT_READ || io->ci_type == CIT_WRITE || io->ci_type == CIT_FAULT) { - if (vio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED) + if (cio->cui_fd->fd_flags & LL_FILE_GROUP_LOCKED) result = -EBUSY; else { desc->cld_start = page->cp_index; @@ -716,8 +716,8 @@ int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io, __u32 enqflags, enum cl_lock_mode mode, pgoff_t start, pgoff_t end) { - struct ccc_io *vio = ccc_env_io(env); - struct cl_lock_descr *descr = &vio->cui_link.cill_descr; + struct ccc_io *cio = ccc_env_io(env); + struct cl_lock_descr *descr = &cio->cui_link.cill_descr; struct cl_object *obj = io->ci_obj; CLOBINVRNT(env, obj, ccc_object_invariant(obj)); @@ -725,23 +725,52 @@ int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io, CDEBUG(D_VFSTRACE, "lock: %i [%lu, %lu]\n", mode, start, end); - memset(&vio->cui_link, 0, sizeof vio->cui_link); + memset(&cio->cui_link, 0, sizeof cio->cui_link); descr->cld_mode = mode; descr->cld_obj = obj; descr->cld_start = start; descr->cld_end = end; - vio->cui_link.cill_enq_flags = enqflags; - cl_io_lock_add(env, io, &vio->cui_link); + cio->cui_link.cill_enq_flags = enqflags; + cl_io_lock_add(env, io, &cio->cui_link); RETURN(0); } +void ccc_io_update_iov(const struct lu_env *env, + struct ccc_io *cio, struct cl_io *io) +{ + int i; + size_t size = io->u.ci_rw.crw_count; + + cio->cui_iov_olen = 0; + if (cl_io_is_sendfile(io) || size == cio->cui_tot_count) + return; + + if (cio->cui_tot_nrsegs == 0) + cio->cui_tot_nrsegs = cio->cui_nrsegs; + + for (i = 0; i < cio->cui_tot_nrsegs; i++) { + struct iovec *iv = &cio->cui_iov[i]; + + if (iv->iov_len < size) + size -= iv->iov_len; + else { + if (iv->iov_len > size) { + cio->cui_iov_olen = iv->iov_len; + iv->iov_len = size; + } + break; + } + } + + cio->cui_nrsegs = i + 1; +} + int ccc_io_one_lock(const struct lu_env *env, struct cl_io *io, __u32 enqflags, enum cl_lock_mode mode, loff_t start, loff_t end) { struct cl_object *obj = io->ci_obj; - return ccc_io_one_lock_index(env, io, enqflags, mode, cl_index(obj, start), cl_index(obj, end)); } @@ -752,6 +781,38 @@ void ccc_io_end(const struct lu_env *env, const struct cl_io_slice *ios) ccc_object_invariant(ios->cis_io->ci_obj)); } +void ccc_io_advance(const struct lu_env *env, + const struct cl_io_slice *ios, + size_t nob) +{ + struct ccc_io *cio = cl2ccc_io(env, ios); + struct cl_io *io = ios->cis_io; + struct cl_object *obj = ios->cis_io->ci_obj; + + CLOBINVRNT(env, obj, ccc_object_invariant(obj)); + + if (!cl_io_is_sendfile(io) && io->ci_continue) { + /* update the iov */ + LASSERT(cio->cui_tot_nrsegs >= cio->cui_nrsegs); + LASSERT(cio->cui_tot_count >= nob); + + cio->cui_iov += cio->cui_nrsegs; + cio->cui_tot_nrsegs -= cio->cui_nrsegs; + cio->cui_tot_count -= nob; + + if (cio->cui_iov_olen) { + struct iovec *iv; + + cio->cui_iov--; + cio->cui_tot_nrsegs++; + iv = &cio->cui_iov[0]; + iv->iov_base += iv->iov_len; + LASSERT(cio->cui_iov_olen > iv->iov_len); + iv->iov_len = cio->cui_iov_olen - iv->iov_len; + } + } +} + static void ccc_object_size_lock(struct cl_object *obj, int vfslock) { struct inode *inode = ccc_object_inode(obj); diff --git a/lustre/liblustre/llite_cl.c b/lustre/liblustre/llite_cl.c index 0a29220..2557dbc 100644 --- a/lustre/liblustre/llite_cl.c +++ b/lustre/liblustre/llite_cl.c @@ -429,9 +429,10 @@ static const struct cl_lock_operations slp_lock_ops = { */ static int slp_io_rw_lock(const struct lu_env *env, - const struct cl_io_slice *ios) + const struct cl_io_slice *ios) { - struct cl_io *io = ios->cis_io; + struct ccc_io *cio = ccc_env_io(env); + struct cl_io *io = ios->cis_io; loff_t start; loff_t end; @@ -442,6 +443,9 @@ static int slp_io_rw_lock(const struct lu_env *env, start = io->u.ci_wr.wr.crw_pos; end = start + io->u.ci_wr.wr.crw_count - 1; } + + ccc_io_update_iov(env, cio, io); + /* * This acquires real DLM lock only in O_APPEND case, because of * the io->ci_lockreq setting in llu_io_init(). @@ -726,9 +730,12 @@ static int slp_io_start(const struct lu_env *env, const struct cl_io_slice *ios) } LASSERT(cnt == 0 || io->ci_type == CIT_READ); /* libsysio should guarantee this */ - session->lis_groups[session->lis_ngroups++] = iogroup; + if (!iogroup->lig_rc) + session->lis_rwcount += iogroup->lig_rwcount; + else if (!session->lis_rc) + session->lis_rc = iogroup->lig_rc; + err = 0; - return 0; out: put_io_group(iogroup); return err; @@ -740,13 +747,15 @@ static const struct cl_io_operations ccc_io_ops = { .cio_fini = ccc_io_fini, .cio_lock = slp_io_rw_lock, .cio_start = slp_io_start, - .cio_end = ccc_io_end + .cio_end = ccc_io_end, + .cio_advance = ccc_io_advance }, [CIT_WRITE] = { .cio_fini = ccc_io_fini, .cio_lock = slp_io_rw_lock, .cio_start = slp_io_start, - .cio_end = ccc_io_end + .cio_end = ccc_io_end, + .cio_advance = ccc_io_advance }, [CIT_TRUNC] = { .cio_fini = ccc_io_fini, diff --git a/lustre/liblustre/llite_lib.h b/lustre/liblustre/llite_lib.h index b9606b4..8c1bec6 100644 --- a/lustre/liblustre/llite_lib.h +++ b/lustre/liblustre/llite_lib.h @@ -327,15 +327,13 @@ static inline void inode_init_lvb(struct inode *inode, struct ost_lvb *lvb) sizeof(cfs_page_t) + \ llap_cookie_size) * (x)) -#define LLU_IO_SESSION_SIZE(x) \ - (sizeof(struct llu_io_session) + (x) * 2 * sizeof(void *)) - struct llu_io_session { struct inode *lis_inode; int lis_cmd; int lis_max_groups; int lis_ngroups; - struct llu_io_group *lis_groups[0]; + int lis_rc; + __u64 lis_rwcount; }; struct llu_io_group diff --git a/lustre/liblustre/rw.c b/lustre/liblustre/rw.c index 89f22d0..7fdf5ae 100644 --- a/lustre/liblustre/rw.c +++ b/lustre/liblustre/rw.c @@ -366,7 +366,7 @@ struct llu_io_session *get_io_session(struct inode *ino, int ngroups, int cmd) { struct llu_io_session *session; - OBD_ALLOC(session, LLU_IO_SESSION_SIZE(ngroups)); + OBD_ALLOC_PTR(session); if (!session) return NULL; @@ -379,17 +379,8 @@ struct llu_io_session *get_io_session(struct inode *ino, int ngroups, int cmd) static void put_io_session(struct llu_io_session *session) { - int i; - - for (i = 0; i < session->lis_ngroups; i++) { - if (session->lis_groups[i]) { - put_io_group(session->lis_groups[i]); - session->lis_groups[i] = NULL; - } - } - I_RELE(session->lis_inode); - OBD_FREE(session, LLU_IO_SESSION_SIZE(session->lis_max_groups)); + OBD_FREE_PTR(session); } static int llu_file_rwx(struct inode *ino, @@ -503,8 +494,6 @@ int llu_iop_write(struct inode *ino, int llu_iop_iodone(struct ioctx *ioctx) { struct llu_io_session *session; - struct llu_io_group *group; - int i, rc = 0; struct lu_env *env; struct cl_io *io; int refcheck; @@ -523,22 +512,12 @@ int llu_iop_iodone(struct ioctx *ioctx) LASSERT(session); LASSERT(!IS_ERR(session)); - for (i = 0; i < session->lis_ngroups; i++) { - group = session->lis_groups[i]; - if (group) { - if (!rc) - rc = group->lig_rc; - if (!rc) - ioctx->ioctx_cc += group->lig_rwcount; - put_io_group(group); - session->lis_groups[i] = NULL; - } - } - - if (rc) { - LASSERT(rc < 0); + if (session->lis_rc == 0) { + ioctx->ioctx_cc = session->lis_rwcount; + } else { + LASSERT(session->lis_rc < 0); ioctx->ioctx_cc = -1; - ioctx->ioctx_errno = -rc; + ioctx->ioctx_errno = -session->lis_rc; } put_io_session(session); diff --git a/lustre/llite/vvp_io.c b/lustre/llite/vvp_io.c index db03b79..0df098a 100644 --- a/lustre/llite/vvp_io.c +++ b/lustre/llite/vvp_io.c @@ -183,36 +183,6 @@ static int vvp_mmap_locks(const struct lu_env *env, RETURN(0); } -static void vvp_io_update_iov(const struct lu_env *env, - struct ccc_io *vio, struct cl_io *io) -{ - int i; - size_t size = io->u.ci_rw.crw_count; - - vio->cui_iov_olen = 0; - if (cl_io_is_sendfile(io) || size == vio->cui_tot_count) - return; - - if (vio->cui_tot_nrsegs == 0) - vio->cui_tot_nrsegs = vio->cui_nrsegs; - - for (i = 0; i < vio->cui_tot_nrsegs; i++) { - struct iovec *iv = &vio->cui_iov[i]; - - if (iv->iov_len < size) - size -= iv->iov_len; - else { - if (iv->iov_len > size) { - vio->cui_iov_olen = iv->iov_len; - iv->iov_len = size; - } - break; - } - } - - vio->cui_nrsegs = i + 1; -} - static int vvp_io_rw_lock(const struct lu_env *env, struct cl_io *io, enum cl_lock_mode mode, loff_t start, loff_t end) { @@ -224,7 +194,7 @@ static int vvp_io_rw_lock(const struct lu_env *env, struct cl_io *io, LASSERT(vvp_env_io(env)->cui_oneshot == 0); ENTRY; - vvp_io_update_iov(env, cio, io); + ccc_io_update_iov(env, cio, io); if (io->u.ci_rw.crw_nonblock) ast_flags |= CEF_NONBLOCK; @@ -631,37 +601,6 @@ static int vvp_io_fault_start(const struct lu_env *env, return result; } -static void vvp_io_advance(const struct lu_env *env, - const struct cl_io_slice *ios, size_t nob) -{ - struct ccc_io *vio = cl2ccc_io(env, ios); - struct cl_io *io = ios->cis_io; - struct cl_object *obj = ios->cis_io->ci_obj; - - CLOBINVRNT(env, obj, ccc_object_invariant(obj)); - - if (!cl_io_is_sendfile(io) && io->ci_continue) { - /* update the iov */ - LASSERT(vio->cui_tot_nrsegs >= vio->cui_nrsegs); - LASSERT(vio->cui_tot_count >= nob); - - vio->cui_iov += vio->cui_nrsegs; - vio->cui_tot_nrsegs -= vio->cui_nrsegs; - vio->cui_tot_count -= nob; - - if (vio->cui_iov_olen) { - struct iovec *iv; - - vio->cui_iov--; - vio->cui_tot_nrsegs++; - iv = &vio->cui_iov[0]; - iv->iov_base += iv->iov_len; - LASSERT(vio->cui_iov_olen > iv->iov_len); - iv->iov_len = vio->cui_iov_olen - iv->iov_len; - } - } -} - static int vvp_io_read_page(const struct lu_env *env, const struct cl_io_slice *ios, const struct cl_page_slice *slice) @@ -934,13 +873,13 @@ static const struct cl_io_operations vvp_io_ops = { .cio_fini = vvp_io_fini, .cio_lock = vvp_io_read_lock, .cio_start = vvp_io_read_start, - .cio_advance = vvp_io_advance + .cio_advance = ccc_io_advance }, [CIT_WRITE] = { .cio_fini = vvp_io_fini, .cio_lock = vvp_io_write_lock, .cio_start = vvp_io_write_start, - .cio_advance = vvp_io_advance + .cio_advance = ccc_io_advance }, [CIT_TRUNC] = { .cio_fini = vvp_io_trunc_fini, -- 1.8.3.1