/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * Lustre Light Super operations
+ * GPL HEADER START
*
- * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * Lustre is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * Lustre is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
- * You should have received a copy of the GNU General Public License
- * along with Lustre; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/liblustre/rw.c
+ *
+ * Lustre Light block IO
*/
#define DEBUG_SUBSYSTEM S_LLITE
#include <stdlib.h>
#include <string.h>
-#include <error.h>
#include <assert.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/queue.h>
+#include <fcntl.h>
+#include <sys/uio.h>
#include <sysio.h>
+#ifdef HAVE_XTIO_H
+#include <xtio.h>
+#endif
#include <fs.h>
#include <mount.h>
#include <inode.h>
+#ifdef HAVE_FILE_H
#include <file.h>
+#endif
#include "llite_lib.h"
-int llu_iop_iodone(struct ioctx *ioctxp __IS_UNUSED)
+typedef ssize_t llu_file_piov_t(const struct iovec *iovec, int iovlen,
+ _SYSIO_OFF_T pos, ssize_t len,
+ void *private);
+
+size_t llap_cookie_size;
+
+static int llu_lock_to_stripe_offset(struct inode *inode, struct ldlm_lock *lock)
{
- return 1;
+ struct llu_inode_info *lli = llu_i2info(inode);
+ struct lov_stripe_md *lsm = lli->lli_smd;
+ struct obd_export *exp = llu_i2obdexp(inode);
+ struct {
+ char name[16];
+ struct ldlm_lock *lock;
+ } key = { .name = KEY_LOCK_TO_STRIPE, .lock = lock };
+ __u32 stripe, vallen = sizeof(stripe);
+ int rc;
+ ENTRY;
+
+ if (lsm->lsm_stripe_count == 1)
+ RETURN(0);
+
+ /* get our offset in the lov */
+ rc = obd_get_info(exp, sizeof(key), &key, &vallen, &stripe, lsm);
+ if (rc != 0) {
+ CERROR("obd_get_info: rc = %d\n", rc);
+ LBUG();
+ }
+ LASSERT(stripe < lsm->lsm_stripe_count);
+ RETURN(stripe);
}
-/*
- * this grabs a lock and manually implements behaviour that makes it look
- * like the OST is returning the file size with each lock acquisition
- */
-int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
- struct lov_stripe_md *lsm,
- int mode, struct ldlm_extent *extent,
- struct lustre_handle *lockh)
+int llu_extent_lock_cancel_cb(struct ldlm_lock *lock,
+ struct ldlm_lock_desc *new, void *data,
+ int flag)
{
-#if 0
- struct ll_inode_info *lli = ll_i2info(inode);
+ struct lustre_handle lockh = { 0 };
int rc;
ENTRY;
- rc = ll_extent_lock_no_validate(fd, inode, lsm, mode, extent, lockh);
- if (rc != ELDLM_OK)
- RETURN(rc);
+ if ((unsigned long)data > 0 && (unsigned long)data < 0x1000) {
+ LDLM_ERROR(lock, "cancelling lock with bad data %p", data);
+ LBUG();
+ }
+
+ switch (flag) {
+ case LDLM_CB_BLOCKING:
+ ldlm_lock2handle(lock, &lockh);
+ rc = ldlm_cli_cancel(&lockh);
+ if (rc != ELDLM_OK)
+ CERROR("ldlm_cli_cancel failed: %d\n", rc);
+ break;
+ case LDLM_CB_CANCELING: {
+ struct inode *inode;
+ struct llu_inode_info *lli;
+ struct lov_stripe_md *lsm;
+ __u32 stripe;
+ __u64 kms;
+
+ /* This lock wasn't granted, don't try to evict pages */
+ if (lock->l_req_mode != lock->l_granted_mode)
+ RETURN(0);
- /* always do a getattr for the first person to pop out of lock
- * acquisition.. the DID_GETATTR flag and semaphore serialize
- * this initial race. we used to make a decision based on whether
- * the lock was matched or acquired, but the matcher could win the
- * waking race with the first issuer so that was no good..
- */
- if (test_bit(LLI_F_DID_GETATTR, &lli->lli_flags))
- RETURN(ELDLM_OK);
-
- down(&lli->lli_getattr_sem);
-
- if (!test_bit(LLI_F_DID_GETATTR, &lli->lli_flags)) {
- rc = ll_inode_getattr(inode, lsm, fd ? &fd->fd_ost_och : NULL);
- if (rc == 0) {
- set_bit(LLI_F_DID_GETATTR, &lli->lli_flags);
- } else {
- /* XXX can this fail? */
- ll_extent_unlock(fd, inode, lsm, mode, lockh);
- }
+ inode = llu_inode_from_lock(lock);
+ if (!inode)
+ RETURN(0);
+ lli= llu_i2info(inode);
+ if (!lli)
+ goto iput;
+ if (!lli->lli_smd)
+ goto iput;
+ lsm = lli->lli_smd;
+
+ stripe = llu_lock_to_stripe_offset(inode, lock);
+ lock_res_and_lock(lock);
+ kms = ldlm_extent_shift_kms(lock,
+ lsm->lsm_oinfo[stripe]->loi_kms);
+ unlock_res_and_lock(lock);
+ if (lsm->lsm_oinfo[stripe]->loi_kms != kms)
+ LDLM_DEBUG(lock, "updating kms from "LPU64" to "LPU64,
+ lsm->lsm_oinfo[stripe]->loi_kms, kms);
+ loi_kms_set(lsm->lsm_oinfo[stripe], kms);
+iput:
+ I_RELE(inode);
+ break;
+ }
+ default:
+ LBUG();
}
- up(&lli->lli_getattr_sem);
+ RETURN(0);
+}
+
+static int llu_glimpse_callback(struct ldlm_lock *lock, void *reqp)
+{
+ struct ptlrpc_request *req = reqp;
+ struct inode *inode = llu_inode_from_lock(lock);
+ struct llu_inode_info *lli;
+ struct ost_lvb *lvb;
+ int rc, stripe = 0;
+ ENTRY;
+
+ if (inode == NULL)
+ GOTO(out, rc = -ELDLM_NO_LOCK_DATA);
+ lli = llu_i2info(inode);
+ if (lli == NULL)
+ GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
+ if (lli->lli_smd == NULL)
+ GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
+
+ /* First, find out which stripe index this lock corresponds to. */
+ if (lli->lli_smd->lsm_stripe_count > 1)
+ stripe = llu_lock_to_stripe_offset(inode, lock);
+
+ req_capsule_extend(&req->rq_pill, &RQF_LDLM_GL_CALLBACK);
+ req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER,
+ sizeof(*lvb));
+ rc = req_capsule_server_pack(&req->rq_pill);
+ if (rc) {
+ CERROR("failed pack reply: %d\n", rc);
+ GOTO(iput, rc);
+ }
+
+ lvb = req_capsule_server_get(&req->rq_pill, &RMF_DLM_LVB);
+ lvb->lvb_size = lli->lli_smd->lsm_oinfo[stripe]->loi_kms;
+
+ LDLM_DEBUG(lock, "i_size: "LPU64" -> stripe number %u -> kms "LPU64,
+ (__u64)llu_i2stat(inode)->st_size, stripe,lvb->lvb_size);
+ iput:
+ I_RELE(inode);
+ out:
+ /* These errors are normal races, so we don't want to fill the console
+ * with messages by calling ptlrpc_error() */
+ if (rc == -ELDLM_NO_LOCK_DATA)
+ lustre_pack_reply(req, 1, NULL, NULL);
+
+ req->rq_status = rc;
+ return rc;
+}
+
+int llu_merge_lvb(struct inode *inode)
+{
+ struct llu_inode_info *lli = llu_i2info(inode);
+ struct llu_sb_info *sbi = llu_i2sbi(inode);
+ struct intnl_stat *st = llu_i2stat(inode);
+ struct ost_lvb lvb;
+ int rc;
+ ENTRY;
+
+ lov_stripe_lock(lli->lli_smd);
+ inode_init_lvb(inode, &lvb);
+ /* merge timestamps the most resently obtained from mds with
+ timestamps obtained from osts */
+ lvb.lvb_atime = lli->lli_lvb.lvb_atime;
+ lvb.lvb_mtime = lli->lli_lvb.lvb_mtime;
+ lvb.lvb_ctime = lli->lli_lvb.lvb_ctime;
+ rc = obd_merge_lvb(sbi->ll_dt_exp, lli->lli_smd, &lvb, 0);
+ st->st_size = lvb.lvb_size;
+ st->st_blocks = lvb.lvb_blocks;
+ /* handle st_blocks overflow gracefully */
+ if (st->st_blocks < lvb.lvb_blocks)
+ st->st_blocks = ~0UL;
+ st->st_mtime = lvb.lvb_mtime;
+ st->st_atime = lvb.lvb_atime;
+ st->st_ctime = lvb.lvb_ctime;
+ lov_stripe_unlock(lli->lli_smd);
+
RETURN(rc);
-#else
- return ELDLM_OK;
-#endif
}
-int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
- struct lov_stripe_md *lsm, int mode,
- struct lustre_handle *lockh)
+int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
+ struct lov_stripe_md *lsm, int mode,
+ ldlm_policy_data_t *policy, struct lustre_handle *lockh,
+ int ast_flags)
{
-#if 0
- struct ll_sb_info *sbi = ll_i2sbi(inode);
+ struct llu_sb_info *sbi = llu_i2sbi(inode);
+ struct intnl_stat *st = llu_i2stat(inode);
+ struct ldlm_enqueue_info einfo = { 0 };
+ struct obd_info oinfo = { { { 0 } } };
+ struct ost_lvb lvb;
int rc;
ENTRY;
+ LASSERT(!lustre_handle_is_used(lockh));
+ CLASSERT(ELDLM_OK == 0);
+
/* XXX phil: can we do this? won't it screw the file size up? */
if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
- (sbi->ll_flags & LL_SBI_NOLCK))
+ (sbi->ll_flags & LL_SBI_NOLCK) || mode == LCK_NL)
RETURN(0);
- rc = obd_cancel(&sbi->ll_osc_conn, lsm, mode, lockh);
+ CDEBUG(D_DLMTRACE, "Locking inode "LPU64", start "LPU64" end "LPU64"\n",
+ (__u64)st->st_ino, policy->l_extent.start,
+ policy->l_extent.end);
+
+ einfo.ei_type = LDLM_EXTENT;
+ einfo.ei_mode = mode;
+ einfo.ei_cb_bl = llu_extent_lock_cancel_cb;
+ einfo.ei_cb_cp = ldlm_completion_ast;
+ einfo.ei_cb_gl = llu_glimpse_callback;
+ einfo.ei_cbdata = inode;
+
+ oinfo.oi_policy = *policy;
+ oinfo.oi_lockh = lockh;
+ oinfo.oi_md = lsm;
+ oinfo.oi_flags = ast_flags;
+
+ rc = obd_enqueue(sbi->ll_dt_exp, &oinfo, &einfo, NULL);
+ *policy = oinfo.oi_policy;
+ if (rc > 0)
+ rc = -EIO;
+
+ inode_init_lvb(inode, &lvb);
+ obd_merge_lvb(sbi->ll_dt_exp, lsm, &lvb, 1);
+ if (policy->l_extent.start == 0 &&
+ policy->l_extent.end == OBD_OBJECT_EOF)
+ st->st_size = lvb.lvb_size;
+
+ if (rc == 0) {
+ st->st_mtime = lvb.lvb_mtime;
+ st->st_atime = lvb.lvb_atime;
+ st->st_ctime = lvb.lvb_ctime;
+ }
RETURN(rc);
-#else
- return 0;
-#endif
}
-static int llu_brw(int cmd, struct inode *inode, struct page *page, int flags)
+int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
+ struct lov_stripe_md *lsm, int mode,
+ struct lustre_handle *lockh)
{
- struct llu_inode_info *lli = llu_i2info(inode);
- struct lov_stripe_md *lsm = lli->lli_smd;
- struct brw_page pg;
+ struct llu_sb_info *sbi = llu_i2sbi(inode);
int rc;
ENTRY;
- pg.pg = page;
- pg.off = ((obd_off)page->index) << PAGE_SHIFT;
-
- /* FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME */
-#if 0
- if (cmd == OBD_BRW_WRITE && (pg.off + PAGE_SIZE > lli->lli_st_size))
- pg.count = lli->lli_st_size % PAGE_SIZE;
- else
-#endif
- pg.count = PAGE_SIZE;
-
- CDEBUG(D_PAGE, "%s %d bytes ino %lu at "LPU64"/"LPX64"\n",
- cmd & OBD_BRW_WRITE ? "write" : "read", pg.count, lli->lli_st_ino,
- pg.off, pg.off);
- if (pg.count == 0) {
- LBUG();
- }
+ CLASSERT(ELDLM_OK == 0);
- pg.flag = flags;
+ /* XXX phil: can we do this? won't it screw the file size up? */
+ if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
+ (sbi->ll_flags & LL_SBI_NOLCK) || mode == LCK_NL)
+ RETURN(0);
- rc = obd_brw(cmd, llu_i2obdconn(inode), lsm, 1, &pg, set, NULL);
- if (rc) {
- CERROR("error from obd_brw: rc = %d\n", rc);
- }
+ rc = obd_cancel(sbi->ll_dt_exp, lsm, mode, lockh);
RETURN(rc);
}
-static int llu_prepare_write(struct inode *inode, struct page *page,
- unsigned from, unsigned to)
+static
+ssize_t llu_file_prwv(const struct iovec *iovec, int iovlen,
+ _SYSIO_OFF_T pos, ssize_t len,
+ void *private)
{
+ struct llu_io_session *session = (struct llu_io_session *) private;
+ struct inode *inode = session->lis_inode;
struct llu_inode_info *lli = llu_i2info(inode);
- obd_off offset = ((obd_off)page->index) << PAGE_SHIFT;
- int rc = 0;
+ int err;
+ struct lu_env *env;
+ struct cl_io *io;
+ struct slp_io *sio;
+ int refcheck;
ENTRY;
-#if 0
- if (!PageLocked(page))
- LBUG();
-
- if (PageUptodate(page))
- RETURN(0);
+ /* in a large iov read/write we'll be repeatedly called.
+ * so give a chance to answer cancel ast here
+ */
+ liblustre_wait_event(0);
- //POISON(addr + from, 0xca, to - from);
-#endif
- /* We're completely overwriting an existing page, so _don't_ set it up
- * to date until commit_write */
- if (from == 0 && to == PAGE_SIZE)
+ if (len == 0 || iovlen == 0)
RETURN(0);
- /* If are writing to a new page, no need to read old data.
- * the extent locking and getattr procedures in ll_file_write have
- * guaranteed that i_size is stable enough for our zeroing needs */
- if (lli->lli_st_size <= offset) {
- memset(kmap(page), 0, PAGE_SIZE);
- kunmap(page);
- GOTO(prepare_done, rc = 0);
+ if (pos + len > lli->lli_maxbytes)
+ RETURN(-ERANGE);
+
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
+
+ io = &ccc_env_info(env)->cti_io;
+
+ if (cl_io_rw_init(env, io, session->lis_cmd == OBD_BRW_WRITE?CIT_WRITE:
+ CIT_READ,
+ pos, len) == 0) {
+ struct ccc_io *cio;
+ sio = slp_env_io(env);
+ cio = ccc_env_io(env);
+ /* XXX this is not right: cio->cui_iov can be modified. */
+ cio->cui_iov = (struct iovec *)iovec;
+ cio->cui_nrsegs = iovlen;
+ cio->cui_tot_nrsegs = iovlen;
+ sio->sio_session = session;
+ err = cl_io_loop(env, io);
+ } else {
+ /* XXX WTF? */
+ LBUG();
}
+ cl_io_fini(env, io);
+ cl_env_put(env, &refcheck);
- rc = llu_brw(OBD_BRW_READ, inode, page, 0);
+ if (err < 0)
+ RETURN(err);
- EXIT;
-
- prepare_done:
- return rc;
+ RETURN(len);
}
-static int llu_commit_write(struct inode *inode, struct page *page,
- unsigned from, unsigned to)
+static
+struct llu_io_session *get_io_session(struct inode *ino, int ngroups, int cmd)
{
- struct llu_inode_info *lli = llu_i2info(inode);
- loff_t size;
- int rc;
- ENTRY;
-#if 0
- LASSERT(inode == file->f_dentry->d_inode);
- LASSERT(PageLocked(page));
-
- CDEBUG(D_INODE, "inode %p is writing page %p from %d to %d at %lu\n",
- inode, page, from, to, page->index);
- CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu,from=%d,to=%d\n",
- inode->i_ino, from, to);
- /* to match full page case in prepare_write */
- SetPageUptodate(page);
- /* mark the page dirty, put it on mapping->dirty,
- * mark the inode PAGES_DIRTY, put it on sb->dirty */
- set_page_dirty(page);
-#endif
- rc = llu_brw(OBD_BRW_WRITE, inode, page, 0);
- if (rc)
- return rc;
+ struct llu_io_session *session;
- /* this is matched by a hack in obdo_to_inode at the moment */
- size = (((obd_off)page->index) << PAGE_SHIFT) + to;
- if (size > lli->lli_st_size)
- lli->lli_st_size = size;
+ OBD_ALLOC_PTR(session);
+ if (!session)
+ return NULL;
- RETURN(0);
-} /* ll_commit_write */
+ I_REF(ino);
+ session->lis_inode = ino;
+ session->lis_max_groups = ngroups;
+ session->lis_cmd = cmd;
+ return session;
+}
-ssize_t
-llu_generic_file_write(struct inode *inode, const char *buf,
- size_t count, loff_t pos)
+static void put_io_session(struct llu_io_session *session)
{
- struct page *page;
- ssize_t written;
- long status = 0;
- int err;
- unsigned bytes;
-
- if ((ssize_t) count < 0)
- return -EINVAL;
-#if 0
- down(&inode->i_sem);
-#endif
- if (pos < 0)
- return -EINVAL;
-
- written = 0;
-
-#if 0
- remove_suid(inode);
- update_inode_times(inode);
-#endif
- do {
- unsigned long index, offset;
- char *kaddr;
-
- /*
- * Try to find the page in the cache. If it isn't there,
- * allocate a free page.
- */
- offset = (pos & (PAGE_CACHE_SIZE -1)); /* Within page */
- index = pos >> PAGE_CACHE_SHIFT;
- bytes = PAGE_CACHE_SIZE - offset;
- if (bytes > count) {
- bytes = count;
- }
-
- status = -ENOMEM; /* we'll assign it later anyway */
- page = __grab_cache_page(index);
- if (!page)
- break;
-
- kaddr = kmap(page);
- status = llu_prepare_write(inode, page, offset, offset+bytes);
- if (status)
- goto sync_failure;
-
- memcpy(kaddr+offset, buf, bytes);
-
- status = llu_commit_write(inode, page, offset, offset+bytes);
- if (!status)
- status = bytes;
-
- if (status >= 0) {
- written += status;
- count -= status;
- pos += status;
- buf += status;
- }
-unlock:
- kunmap(page);
- page_cache_release(page);
-
- if (status < 0)
- break;
- } while (count);
-done:
- err = written ? written : status;
-
-#if 0
- up(&inode->i_sem);
-#endif
- return err;
-
- status = -EFAULT;
- goto unlock;
-
-sync_failure:
- /*
- * If blocksize < pagesize, prepare_write() may have instantiated a
- * few blocks outside i_size. Trim these off again.
- */
- kunmap(page);
- page_cache_release(page);
- goto done;
+ I_RELE(session->lis_inode);
+ OBD_FREE_PTR(session);
}
-ssize_t llu_file_write(struct inode *inode, const struct iovec *iovec,
- size_t iovlen, loff_t pos)
+static int llu_file_rwx(struct inode *ino,
+ struct ioctx *ioctx,
+ int read)
{
- struct llu_inode_info *lli = llu_i2info(inode);
- struct ll_file_data *fd = lli->lli_file_data; /* XXX not ready don't use it now */
- struct lustre_handle lockh = { 0 };
- struct lov_stripe_md *lsm = lli->lli_smd;
- struct ldlm_extent extent;
- ldlm_error_t err;
- ssize_t retval = 0;
+ struct llu_io_session *session;
+ ssize_t cc;
+ int cmd = read ? OBD_BRW_READ : OBD_BRW_WRITE;
ENTRY;
- /* XXX consider other types later */
- if (!S_ISREG(lli->lli_st_mode))
- LBUG();
-#if 0
- CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu,size="LPSZ",offset=%Ld\n",
- inode->i_ino, count, *ppos);
-
- /*
- * sleep doing some writeback work of this mount's dirty data
- * if the VM thinks we're low on memory.. other dirtying code
- * paths should think about doing this, too, but they should be
- * careful not to hold locked pages while they do so. like
- * ll_prepare_write. *cough*
- */
- ll_check_dirty(inode->i_sb);
-#endif
- while (iovlen--) {
- const char *buf = iovec[iovlen].iov_base;
- size_t count = iovec[iovlen].iov_len;
-
- /* POSIX, but surprised the VFS doesn't check this already */
- if (count == 0)
- continue;
-
-#if 0
- if (!S_ISBLK(lli->lli_st_mode) && file->f_flags & O_APPEND) {
- extent.start = 0;
- extent.end = OBD_OBJECT_EOF;
- } else {
- extent.start = *ppos;
- extent.end = *ppos + count - 1;
- }
-#else
- extent.start = pos;
- extent.end = pos + count - 1;
-#endif
+ LASSERT(ioctx->ioctx_xtvlen >= 0);
+ LASSERT(ioctx->ioctx_iovlen >= 0);
- err = llu_extent_lock(fd, inode, lsm, LCK_PW, &extent, &lockh);
- if (err != ELDLM_OK)
- RETURN(-ENOLCK);
+ liblustre_wait_event(0);
-#if 0
- if (!S_ISBLK(inode->i_mode) && file->f_flags & O_APPEND)
- *ppos = inode->i_size;
+ if (!ioctx->ioctx_xtvlen)
+ RETURN(0);
- CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
- inode->i_ino, count, *ppos);
-#endif
- retval += llu_generic_file_write(inode, buf, count, pos);
+ /* XXX consider other types later */
+ if (S_ISDIR(llu_i2stat(ino)->st_mode))
+ RETURN(-EISDIR);
+ if (!S_ISREG(llu_i2stat(ino)->st_mode))
+ RETURN(-EOPNOTSUPP);
+
+ session = get_io_session(ino, ioctx->ioctx_xtvlen * 2, cmd);
+ if (!session)
+ RETURN(-ENOMEM);
+
+ cc = _sysio_enumerate_extents(ioctx->ioctx_xtv, ioctx->ioctx_xtvlen,
+ ioctx->ioctx_iov, ioctx->ioctx_iovlen,
+ llu_file_prwv, session);
+
+ if (cc >= 0) {
+ LASSERT(!ioctx->ioctx_cc);
+ ioctx->ioctx_private = session;
+ cc = 0;
+ } else {
+ put_io_session(session);
}
- /* XXX errors? */
- ll_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
- return(retval);
+ liblustre_wait_event(0);
+ RETURN(cc);
}
-static void llu_update_atime(struct inode *inode)
+void llu_io_init(struct cl_io *io, struct inode *inode, int write)
{
-#if 0
struct llu_inode_info *lli = llu_i2info(inode);
-#ifdef USE_ATIME
- struct iattr attr;
+ memset(io, 0, sizeof *io);
- attr.ia_atime = LTIME_S(CURRENT_TIME);
- attr.ia_valid = ATTR_ATIME;
+ io->u.ci_rw.crw_nonblock = lli->lli_open_flags & O_NONBLOCK;
+ if (write)
+ io->u.ci_wr.wr_append = lli->lli_open_flags & O_APPEND;
+ io->ci_obj = llu_i2info(inode)->lli_clob;
- if (lli->lli_st_atime == attr.ia_atime) return;
- if (IS_RDONLY(inode)) return;
- if (IS_NOATIME(inode)) return;
-
- /* ll_inode_setattr() sets inode->i_atime from attr.ia_atime */
- llu_inode_setattr(inode, &attr, 0);
-#else
- /* update atime, but don't explicitly write it out just this change */
- inode->i_atime = CURRENT_TIME;
-#endif
-#endif
+ if ((lli->lli_open_flags & O_APPEND) && write)
+ io->ci_lockreq = CILR_MANDATORY;
+ else
+ io->ci_lockreq = CILR_NEVER;
}
-static size_t llu_generic_file_read(struct inode *inode, char *buf,
- size_t count, loff_t pos)
+int llu_iop_read(struct inode *ino,
+ struct ioctx *ioctx)
{
- struct llu_inode_info *lli = llu_i2info(inode);
- unsigned long index, offset;
- int error = 0;
- size_t readed = 0;
-
- index = pos >> PAGE_CACHE_SHIFT;
- offset = pos & ~PAGE_CACHE_MASK;
-
- do {
- struct page *page;
- unsigned long end_index, nr;
-
- end_index = lli->lli_st_size >> PAGE_CACHE_SHIFT;
-
- if (index > end_index)
- break;
- nr = PAGE_CACHE_SIZE;
- if (index == end_index) {
- nr = lli->lli_st_size & ~PAGE_CACHE_MASK;
- if (nr <= offset)
- break;
- }
-
- nr = nr - offset;
- if (nr > count)
- nr = count;
-
- page = grab_cache_page(index);
- if (!page) {
- error = -ENOMEM;
- break;
- }
-
- error = llu_brw(OBD_BRW_READ, inode, page, 0);
- if (error) {
- page_cache_release(page);
- break;
- }
-
- memcpy(buf, kmap(page)+offset, nr);
- offset += nr;
- index += offset >> PAGE_CACHE_SHIFT;
- offset &= ~PAGE_CACHE_MASK;
- readed += nr;
- count -= nr;
-
- page_cache_release(page);
- } while (count);
-
- if (error)
- return error;
- return readed;
+ struct intnl_stat *st = llu_i2stat(ino);
+ struct lu_env *env;
+ struct cl_io *io;
+ int refcheck;
+ int ret;
+
+ /* BUG: 5972 */
+ st->st_atime = CFS_CURRENT_TIME;
+
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
+
+ io = &ccc_env_info(env)->cti_io;
+ llu_io_init(io, ino, 0);
+
+ ret = llu_file_rwx(ino, ioctx, 1);
+
+ cl_env_put(env, &refcheck);
+ return ret;
}
-ssize_t llu_file_read(struct inode *inode, const struct iovec *iovec,
- size_t iovlen, loff_t pos)
+int llu_iop_write(struct inode *ino,
+ struct ioctx *ioctx)
{
- struct llu_inode_info *lli = llu_i2info(inode);
- struct ll_file_data *fd = lli->lli_file_data;
- struct lov_stripe_md *lsm = lli->lli_smd;
- struct lustre_handle lockh = { 0 };
-#if 0
- struct ll_read_extent rextent;
-#else
- struct ldlm_extent extent;
-#endif
- ldlm_error_t err;
- ssize_t retval = 0;
- ENTRY;
+ struct intnl_stat *st = llu_i2stat(ino);
+ struct lu_env *env;
+ struct cl_io *io;
+ int refcheck;
+ int ret;
- while (iovlen--) {
- char *buf = iovec[iovlen].iov_base;
- size_t count = iovec[iovlen].iov_len;
+ st->st_mtime = st->st_ctime = CFS_CURRENT_TIME;
- /* "If nbyte is 0, read() will return 0 and have no other results."
- * -- Single Unix Spec */
- if (count == 0)
- RETURN(0);
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
-#if 0
- rextent.re_extent.start = pos;
- rextent.re_extent.end = pos + count - 1;
-#else
- extent.start = pos;
- extent.end = pos + count - 1;
-#endif
- err = llu_extent_lock(fd, inode, lsm, LCK_PR, &extent, &lockh);
- if (err != ELDLM_OK)
- RETURN(-ENOLCK);
-#if 0
- rextent.re_task = current;
- spin_lock(&lli->lli_read_extent_lock);
- list_add(&rextent.re_lli_item, &lli->lli_read_extents);
- spin_unlock(&lli->lli_read_extent_lock);
-#endif
- CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld\n",
- lli->lli_st_ino, count, pos);
- retval = llu_generic_file_read(inode, buf, count, pos);
-#if 0
- spin_lock(&lli->lli_read_extent_lock);
- list_del(&rextent.re_lli_item);
- spin_unlock(&lli->lli_read_extent_lock);
-#endif
+ io = &ccc_env_info(env)->cti_io;
+ llu_io_init(io, ino, 1);
+
+ ret = llu_file_rwx(ino, ioctx, 0);
+ cl_env_put(env, &refcheck);
+ return ret;
+}
+
+int llu_iop_iodone(struct ioctx *ioctx)
+{
+ struct llu_io_session *session;
+ struct lu_env *env;
+ struct cl_io *io;
+ int refcheck;
+ ENTRY;
+
+ liblustre_wait_event(0);
+
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
+
+ io = &ccc_env_info(env)->cti_io;
+ cl_io_fini(env, io);
+ cl_env_put(env, &refcheck);
+ session = (struct llu_io_session *) ioctx->ioctx_private;
+ LASSERT(session);
+ LASSERT(!IS_ERR(session));
+
+ if (session->lis_rc == 0) {
+ ioctx->ioctx_cc = session->lis_rwcount;
+ } else {
+ LASSERT(session->lis_rc < 0);
+ ioctx->ioctx_cc = -1;
+ ioctx->ioctx_errno = -session->lis_rc;
}
- if (retval > 0)
- llu_update_atime(inode);
+ put_io_session(session);
+ ioctx->ioctx_private = NULL;
+ liblustre_wait_event(0);
- /* XXX errors? */
- ll_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
- RETURN(retval);
+ RETURN(1);
}
-