/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * Lustre Light Super operations
+ * Lustre Light file operations
*
- * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
+ * Copyright (c) 2002-2004 Cluster File Systems, Inc.
*
* This file is part of Lustre, http://www.lustre.org.
*
#include <time.h>
#include <sys/types.h>
#include <sys/queue.h>
+#include <fcntl.h>
+#include <xtio.h>
#include <sysio.h>
#include <fs.h>
#include <mount.h>
/* already opened? */
if (lli->lli_open_count++)
RETURN(0);
-
+
LASSERT(!lli->lli_file_data);
OBD_ALLOC(fd, sizeof(*fd));
fd->fd_mds_och.och_magic = OBD_CLIENT_HANDLE_MAGIC;
lli->lli_file_data = fd;
- mdc_set_open_replay_data(&fd->fd_mds_och, it->d.lustre.it_data);
+ mdc_set_open_replay_data(NULL, &fd->fd_mds_och, it->d.lustre.it_data);
RETURN(0);
}
int rc = 0;
ENTRY;
+ liblustre_wait_event(0);
+
/* don't do anything for '/' */
if (llu_is_root_inode(inode))
RETURN(0);
}
fd->fd_flags &= ~O_LOV_DELAY_CREATE;
+ lli->lli_open_flags = flags & ~(O_CREAT | O_EXCL | O_TRUNC);
+
out_release:
request = it->d.lustre.it_data;
ptlrpc_req_finished(request);
it->it_op_release(it);
OBD_FREE(it, sizeof(*it));
+ /* libsysio haven't doing anything for O_TRUNC. here we
+ * simply simulate it as open(...); truncate(...);
+ */
+ if (rc == 0 && (flags & O_TRUNC) &&
+ S_ISREG(lli->lli_st_mode)) {
+ struct iattr attr;
+
+ memset(&attr, 0, sizeof(attr));
+ attr.ia_size = 0;
+ attr.ia_valid |= ATTR_SIZE | ATTR_RAW;
+ rc = llu_setattr_raw(inode, &attr);
+ if (rc) {
+ CERROR("error %d truncate in open()\n", rc);
+ }
+ }
+
RETURN(rc);
}
int rc, valid;
ENTRY;
- valid = OBD_MD_FLID;
+ /* clear group lock, if present */
+ if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
+ struct lov_stripe_md *lsm = llu_i2info(inode)->lli_smd;
+ fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
+ rc = llu_extent_unlock(fd, inode, lsm, LCK_GROUP,
+ &fd->fd_cwlockh);
+ }
+
+ obdo.o_id = lli->lli_st_ino;
+ obdo.o_valid = OBD_MD_FLID;
+ valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLSIZE |OBD_MD_FLBLOCKS |
+ OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
- memset(&obdo, 0, sizeof(obdo));
- obdo.o_id = lli->lli_st_ino;
- obdo.o_mode = lli->lli_st_mode;
- obdo.o_size = lli->lli_st_size;
- obdo.o_blocks = lli->lli_st_blocks;
+ obdo_from_inode(&obdo, inode, valid);
+
if (0 /* ll_is_inode_dirty(inode) */) {
obdo.o_flags = MDS_BFLAG_UNCOMMITTED_WRITES;
- valid |= OBD_MD_FLFLAGS;
+ obdo.o_valid |= OBD_MD_FLFLAGS;
}
- obdo.o_valid = valid;
rc = mdc_close(mdc_exp, &obdo, och, &req);
if (rc == EAGAIN) {
/* We are the last writer, so the MDS has instructed us to get
//ll_queue_done_writing(inode);
rc = 0;
} else if (rc) {
- CERROR("inode %lu close failed: rc = %d\n", lli->lli_st_ino, rc);
+ CERROR("inode %lu close failed: rc %d\n", lli->lli_st_ino, rc);
} else {
rc = llu_objects_destroy(req, inode);
if (rc)
lli->lli_st_ino, rc);
}
- mdc_clear_open_replay_data(och);
+ mdc_clear_open_replay_data(NULL, och);
ptlrpc_req_finished(req);
och->och_fh.cookie = DEAD_HANDLE_MAGIC;
lli->lli_file_data = NULL;
CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%lu\n", lli->lli_st_ino,
lli->lli_st_generation);
- /* XXX don't do anything for '/'. but how to find the root pnode? */
+ if (llu_is_root_inode(inode))
+ RETURN(0);
/* still opened by others? */
if (--lli->lli_open_count)
RETURN(rc);
}
+/*
+ * libsysio require us return 0
+ */
int llu_iop_close(struct inode *inode)
{
int rc;
+ liblustre_wait_event(0);
+
rc = llu_file_release(inode);
- if (!llu_i2info(inode)->lli_open_count)
- llu_i2info(inode)->lli_stale_flag = 1;
- return rc;
+ if (rc) {
+ CERROR("file close error %d\n", rc);
+ }
+ /* if open count == 0 && stale_flag is set, should we
+ * remove the inode immediately? */
+ return 0;
}
-int llu_iop_ipreadv(struct inode *ino,
- struct ioctx *ioctx)
+_SYSIO_OFF_T llu_iop_pos(struct inode *ino, _SYSIO_OFF_T off)
{
ENTRY;
- if (!ioctx->ioctx_iovlen)
- RETURN(0);
- if (ioctx->ioctx_iovlen < 0)
- RETURN(-EINVAL);
-
- ioctx->ioctx_private = llu_file_read(ino,
- ioctx->ioctx_iovec,
- ioctx->ioctx_iovlen,
- ioctx->ioctx_offset);
- if (IS_ERR(ioctx->ioctx_private))
- return (PTR_ERR(ioctx->ioctx_private));
+ liblustre_wait_event(0);
- RETURN(0);
-}
-
-int llu_iop_ipwritev(struct inode *ino,
- struct ioctx *ioctx)
-{
- ENTRY;
-
- if (!ioctx->ioctx_iovlen)
- RETURN(0);
- if (ioctx->ioctx_iovlen < 0)
+ if (off < 0 || off > ll_file_maxbytes(ino))
RETURN(-EINVAL);
- ioctx->ioctx_private = llu_file_write(ino,
- ioctx->ioctx_iovec,
- ioctx->ioctx_iovlen,
- ioctx->ioctx_offset);
- if (IS_ERR(ioctx->ioctx_private))
- return (PTR_ERR(ioctx->ioctx_private));
-
- RETURN(0);
+ RETURN(off);
}
/* this isn't where truncate starts. roughly: