* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, Whamcloud, Inc.
+ * Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#define DEBUG_SUBSYSTEM S_LLITE
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
-#include <assert.h>
#include <time.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/queue.h>
-#include <fcntl.h>
+#include <sys/types.h>
#include <sys/uio.h>
-
+#include <libcfs/libcfs.h>
+#include <lustre/lustre_idl.h>
+#include <liblustre.h>
+#include <cl_object.h>
+#include <lclient.h>
+#include <lustre_dlm.h>
+#include <obd.h>
+#include <obd_class.h>
+#include <obd_support.h>
#include "llite_lib.h"
-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)
-{
- 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);
-}
-
-int llu_extent_lock_cancel_cb(struct ldlm_lock *lock,
- struct ldlm_lock_desc *new, void *data,
- int flag)
-{
- struct lustre_handle lockh = { 0 };
- int rc;
- ENTRY;
-
- 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);
-
- 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();
- }
-
- 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);
-}
-
-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)
-{
- 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) || mode == LCK_NL)
- RETURN(0);
-
- 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);
-}
-
-int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
- struct lov_stripe_md *lsm, int mode,
- struct lustre_handle *lockh)
+int llu_merge_lvb(const struct lu_env *env, struct inode *inode)
{
- struct llu_sb_info *sbi = llu_i2sbi(inode);
- int rc;
- ENTRY;
-
- 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) || mode == LCK_NL)
- RETURN(0);
-
- rc = obd_cancel(sbi->ll_dt_exp, lsm, mode, lockh);
-
- RETURN(rc);
+ struct llu_inode_info *lli = llu_i2info(inode);
+ struct cl_object *obj = lli->lli_clob;
+ struct intnl_stat *st = llu_i2stat(inode);
+ struct cl_attr *attr = ccc_env_thread_attr(env);
+ struct ost_lvb lvb;
+ int rc;
+ ENTRY;
+
+ /* merge timestamps the most recently obtained from mds with
+ timestamps obtained from osts */
+ LTIME_S(inode->i_atime) = lli->lli_lvb.lvb_atime;
+ LTIME_S(inode->i_mtime) = lli->lli_lvb.lvb_mtime;
+ LTIME_S(inode->i_ctime) = lli->lli_lvb.lvb_ctime;
+
+ inode_init_lvb(inode, &lvb);
+
+ cl_object_attr_lock(obj);
+ rc = cl_object_attr_get(env, obj, attr);
+ cl_object_attr_unlock(obj);
+ if (rc == 0) {
+ if (lvb.lvb_atime < attr->cat_atime)
+ lvb.lvb_atime = attr->cat_atime;
+ if (lvb.lvb_ctime < attr->cat_ctime)
+ lvb.lvb_ctime = attr->cat_ctime;
+ if (lvb.lvb_mtime < attr->cat_mtime)
+ lvb.lvb_mtime = attr->cat_mtime;
+
+ st->st_size = lvb.lvb_size;
+ st->st_blocks = lvb.lvb_blocks;
+ st->st_mtime = lvb.lvb_mtime;
+ st->st_atime = lvb.lvb_atime;
+ st->st_ctime = lvb.lvb_ctime;
+ }
+
+ RETURN(rc);
}
static
I_REF(ino);
session->lis_inode = ino;
- session->lis_max_groups = ngroups;
session->lis_cmd = cmd;
return session;
}