/* -*- 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>
+#ifdef HAVE_XTIO_H
+#include <xtio.h>
+#endif
#include <sysio.h>
#include <fs.h>
#include <mount.h>
#include <inode.h>
+#ifdef HAVE_FILE_H
#include <file.h>
+#endif
+
+#undef LIST_HEAD
#include "llite_lib.h"
-void llu_prepare_mdc_op_data(struct mdc_op_data *data,
- struct inode *i1,
- struct inode *i2,
- const char *name,
- int namelen,
- int mode)
+void llu_prepare_mdc_data(struct mdc_op_data *data, struct inode *i1,
+ struct inode *i2, const char *name,
+ int namelen, int mode)
{
LASSERT(i1);
- ll_i2uctxt(&data->ctxt, i1, i2);
- ll_inode2fid(&data->fid1, i1);
-
- if (i2) {
- ll_inode2fid(&data->fid2, i2);
- }
+ ll_inode2id(&data->id1, i1);
+ if (i2)
+ ll_inode2id(&data->id2, i2);
+ data->valid = 0;
data->name = name;
data->namelen = namelen;
data->create_mode = mode;
data->mod_time = CURRENT_TIME;
}
+static void llu_inode2mdc_data(struct mdc_op_data *op_data,
+ struct inode *inode,
+ obd_valid valid)
+{
+ struct llu_inode_info *lli = llu_i2info(inode);
+ obd_valid newvalid = 0;
+
+ LASSERT(op_data != NULL);
+ LASSERT(inode != NULL);
+
+ /* put object id there all the time. */
+ if (valid & OBD_MD_FLID) {
+ ll_inode2id(&op_data->id1, inode);
+ newvalid |= OBD_MD_FLID;
+ }
+
+ if (valid & OBD_MD_FLSIZE) {
+ op_data->size = lli->lli_st_size;
+ newvalid |= OBD_MD_MEA;
+ }
+ if (valid & OBD_MD_FLBLOCKS) {
+ op_data->blocks = lli->lli_st_blocks;
+ newvalid |= OBD_MD_FLBLOCKS;
+ }
+ if (valid & OBD_MD_FLFLAGS) {
+ op_data->flags = lli->lli_st_flags;
+ newvalid |= OBD_MD_FLFLAGS;
+ }
+ if (valid & OBD_MD_FLATIME) {
+ op_data->atime = LTIME_S(lli->lli_st_atime);
+ newvalid |= OBD_MD_FLATIME;
+ }
+ if (valid & OBD_MD_FLMTIME) {
+ op_data->mtime = LTIME_S(lli->lli_st_mtime);
+ newvalid |= OBD_MD_FLMTIME;
+ }
+ if (valid & OBD_MD_FLCTIME) {
+ op_data->ctime = LTIME_S(lli->lli_st_ctime);
+ newvalid |= OBD_MD_FLCTIME;
+ }
+
+ if (valid & OBD_MD_FLTYPE) {
+ op_data->mode = (op_data->mode & S_IALLUGO) |
+ (lli->lli_st_mode & S_IFMT);
+ newvalid |= OBD_MD_FLTYPE;
+ }
+
+ if (valid & OBD_MD_FLMODE) {
+ op_data->mode = (op_data->mode & S_IFMT) |
+ (lli->lli_st_mode & S_IALLUGO);
+ newvalid |= OBD_MD_FLMODE;
+ }
+
+ op_data->valid |= newvalid;
+}
+
void obdo_refresh_inode(struct inode *dst,
struct obdo *src,
- obd_flag valid)
+ obd_valid valid)
{
struct llu_inode_info *lli = llu_i2info(dst);
valid &= src->o_valid;
if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
- CDEBUG(D_INODE, "valid %x, cur time %lu/%lu, new %lu/%lu\n",
+ CDEBUG(D_INODE, "valid "LPX64", cur time %lu/%lu, new %lu/%lu\n",
src->o_valid, LTIME_S(lli->lli_st_mtime),
LTIME_S(lli->lli_st_ctime),
(long)src->o_mtime, (long)src->o_ctime);
lli->lli_st_blocks = src->o_blocks;
}
-#if 0
-static int llu_create_obj(struct lustre_handle *conn, struct inode *inode,
- struct lov_stripe_md *lsm)
-{
- struct ptlrpc_request *req = NULL;
- struct llu_inode_info *lli = llu_i2info(inode);
- struct lov_mds_md *lmm = NULL;
- struct obdo *oa;
- struct iattr iattr;
- struct mdc_op_data op_data;
- struct obd_trans_info oti = { 0 };
- int rc, err, lmm_size = 0;;
- ENTRY;
-
- oa = obdo_alloc();
- if (!oa)
- RETURN(-ENOMEM);
-
- LASSERT(S_ISREG(inode->i_mode));
- oa->o_mode = S_IFREG | 0600;
- oa->o_id = lli->lli_st_ino;
- oa->o_generation = lli->lli_st_generation;
- /* Keep these 0 for now, because chown/chgrp does not change the
- * ownership on the OST, and we don't want to allow BA OST NFS
- * users to access these objects by mistake.
- */
- oa->o_uid = 0;
- oa->o_gid = 0;
- oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE |
- OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID;
-
- obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|OBD_MD_FLMTIME|
- OBD_MD_FLCTIME |
- (llu_i2info(inode)->lli_st_size ? OBD_MD_FLSIZE : 0));
-
- rc = obd_create(conn, oa, &lsm, &oti);
- if (rc) {
- CERROR("error creating objects for inode %lu: rc = %d\n",
- lli->lli_st_ino, rc);
- if (rc > 0) {
- CERROR("obd_create returned invalid rc %d\n", rc);
- rc = -EIO;
- }
- GOTO(out_oa, rc);
- }
- obdo_refresh_inode(inode, oa, OBD_MD_FLBLKSZ);
-
- LASSERT(lsm && lsm->lsm_object_id);
- rc = obd_packmd(conn, &lmm, lsm);
- if (rc < 0)
- GOTO(out_destroy, rc);
-
- lmm_size = rc;
-
- /* Save the stripe MD with this file on the MDS */
- memset(&iattr, 0, sizeof(iattr));
- iattr.ia_valid = ATTR_FROM_OPEN;
-
- llu_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
-
- rc = mdc_setattr(&llu_i2sbi(inode)->ll_mdc_conn, &op_data,
- &iattr, lmm, lmm_size, oti.oti_logcookies,
- oti.oti_numcookies * sizeof(oti.oti_onecookie), &req);
- ptlrpc_req_finished(req);
-
- obd_free_diskmd(conn, &lmm);
-
- /* If we couldn't complete mdc_open() and store the stripe MD on the
- * MDS, we need to destroy the objects now or they will be leaked.
- */
- if (rc) {
- CERROR("error: storing stripe MD for %lu: rc %d\n",
- lli->lli_st_ino, rc);
- GOTO(out_destroy, rc);
- }
- lli->lli_smd = lsm;
- lli->lli_maxbytes = lsm->lsm_maxbytes;
-
- EXIT;
-out_oa:
- oti_free_cookies(&oti);
- obdo_free(oa);
- return rc;
-
-out_destroy:
- oa->o_id = lsm->lsm_object_id;
- oa->o_valid = OBD_MD_FLID;
- obdo_from_inode(oa, inode, OBD_MD_FLTYPE);
-
- err = obd_destroy(conn, oa, lsm, NULL);
- obd_free_memmd(conn, &lsm);
- if (err) {
- CERROR("error uncreating inode %lu objects: rc %d\n",
- lli->lli_st_ino, err);
- }
- goto out_oa;
-}
-#endif
-
static int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it)
{
- struct ptlrpc_request *req = it->d.lustre.it_data;
+ struct ptlrpc_request *req = LUSTRE_IT(it)->it_data;
struct ll_file_data *fd;
struct mds_body *body;
ENTRY;
/* already opened? */
if (lli->lli_open_count++)
RETURN(0);
-
+
LASSERT(!lli->lli_file_data);
OBD_ALLOC(fd, sizeof(*fd));
/* We can't handle this well without reorganizing ll_file_open and
- * ll_mdc_close, so don't even try right now. */
+ * ll_md_close(), so don't even try right now. */
LASSERT(fd != NULL);
- memset(fd, 0, sizeof(*fd));
-
memcpy(&fd->fd_mds_och.och_fh, &body->handle, sizeof(body->handle));
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, LUSTRE_IT(it)->it_data);
RETURN(0);
}
-#if 0
-static int llu_osc_open(struct lustre_handle *conn, struct inode *inode,
- struct lov_stripe_md *lsm)
-{
- struct ll_file_data *fd = llu_i2info(inode)->lli_file_data;
- struct obdo *oa;
- int rc;
- ENTRY;
-
- oa = obdo_alloc();
- if (!oa)
- RETURN(-ENOMEM);
- oa->o_id = lsm->lsm_object_id;
- oa->o_mode = S_IFREG;
- oa->o_valid = (OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLBLOCKS |
- OBD_MD_FLMTIME | OBD_MD_FLCTIME);
- rc = obd_open(conn, oa, lsm, NULL, &fd->fd_ost_och);
- if (rc)
- GOTO(out, rc);
-
- /* file->f_flags &= ~O_LOV_DELAY_CREATE; */
- obdo_to_inode(inode, oa, OBD_MD_FLBLOCKS | OBD_MD_FLMTIME |
- OBD_MD_FLCTIME);
-
- EXIT;
-out:
- obdo_free(oa);
- return rc;
-}
-#endif
-
-
int llu_iop_open(struct pnode *pnode, int flags, mode_t mode)
{
struct inode *inode = pnode->p_base->pb_ino;
int rc = 0;
ENTRY;
+ liblustre_wait_event(0);
+
+ /* don't do anything for '/' */
+ if (llu_is_root_inode(inode))
+ RETURN(0);
+
CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", lli->lli_st_ino);
LL_GET_INTENT(inode, it);
- if (!it->d.lustre.it_disposition) {
-#if 0
- struct lookup_intent oit = { .it_op = IT_OPEN,
- .it_flags = file->f_flags };
- it = &oit;
- rc = ll_intent_file_open(file, NULL, 0, it);
- if (rc)
- GOTO(out_release, rc);
-#endif
- CERROR("fixme!!\n");
- }
+ if (!LUSTRE_IT(it)->it_disposition)
+ LBUG();
rc = it_open_error(DISP_OPEN_OPEN, it);
if (rc)
CDEBUG(D_INODE, "object creation was delayed\n");
GOTO(out_release, rc);
}
-#if 0
- if (!lli->lli_smd) {
- rc = llu_create_obj(conn, inode, NULL);
- if (rc)
- GOTO(out_close, rc);
- } else {
- CERROR("warning: stripe already set on ino %lu\n",
- lli->lli_st_ino);
- }
- lsm = lli->lli_smd;
-#endif
}
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;
+ request = LUSTRE_IT(it)->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);
}
GOTO(out, rc = -EPROTO);
}
- rc = obd_unpackmd(llu_i2obdexp(dir), &lsm, eadata, body->eadatasize);
+ rc = obd_unpackmd(llu_i2dtexp(dir), &lsm, eadata, body->eadatasize);
if (rc < 0) {
CERROR("obd_unpackmd: %d\n", rc);
GOTO(out, rc);
}
}
- rc = obd_destroy(llu_i2obdexp(dir), oa, lsm, &oti);
+ rc = obd_destroy(llu_i2dtexp(dir), oa, lsm, &oti);
obdo_free(oa);
if (rc)
CERROR("obd destroy objid 0x"LPX64" error %d\n",
lsm->lsm_object_id, rc);
out_free_memmd:
- obd_free_memmd(llu_i2obdexp(dir), &lsm);
+ obd_free_memmd(llu_i2dtexp(dir), &lsm);
out:
return rc;
}
struct ll_file_data *fd = lli->lli_file_data;
struct ptlrpc_request *req = NULL;
struct obd_client_handle *och = &fd->fd_mds_och;
- struct obdo obdo;
+ struct mdc_op_data op_data;
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);
+ }
+
+ memset(&op_data, 0, sizeof(op_data));
+ id_ino(&op_data.id1) = lli->lli_st_ino;
+ op_data.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;
+ llu_inode2mdc_data(&op_data, inode, valid);
+
if (0 /* ll_is_inode_dirty(inode) */) {
- obdo.o_flags = MDS_BFLAG_UNCOMMITTED_WRITES;
- valid |= OBD_MD_FLFLAGS;
+ op_data.flags = MDS_BFLAG_UNCOMMITTED_WRITES;
+ op_data.valid |= OBD_MD_FLFLAGS;
}
- obdo.o_valid = valid;
- rc = mdc_close(mdc_exp, &obdo, och, &req);
+ rc = mdc_close(mdc_exp, &op_data, och, &req);
if (rc == EAGAIN) {
/* We are the last writer, so the MDS has instructed us to get
* the file size and any write cookies, then close again. */
//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);
- /* FIXME need add this check later. how to find the root pnode? */
-#if 0
- /* don't do anything for / */
- if (inode->i_sb->s_root == file->f_dentry)
+ if (llu_is_root_inode(inode))
RETURN(0);
-#endif
+
/* still opened by others? */
if (--lli->lli_open_count)
RETURN(0);
if (!fd) /* no process opened the file after an mcreate */
RETURN(0);
- rc2 = llu_mdc_close(sbi->ll_mdc_exp, inode);
+ rc2 = llu_mdc_close(sbi->ll_md_exp, inode);
if (rc2 && !rc)
rc = rc2;
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:
oa.o_id, lli->lli_st_size);
/* truncate == punch from new size to absolute end of file */
- err = obd_punch(llu_i2obdexp(inode), &oa, lsm, lli->lli_st_size,
- OBD_OBJECT_EOF, NULL);
+ /* XXX: capa is NULL here, is it correct? */
+ err = obd_punch(llu_i2dtexp(inode), &oa, lsm, lli->lli_st_size,
+ OBD_OBJECT_EOF, NULL, NULL);
if (err)
CERROR("obd_truncate fails (%d) ino %lu\n", err, lli->lli_st_ino);
else