#include <lustre_lite.h>
#include <linux/pagemap.h>
#include <linux/file.h>
+#include <linux/sched.h>
#include "llite_internal.h"
#include <lustre/ll_fiemap.h>
+#include <lustre_ioctl.h>
#include "cl_object.h"
const char *name = file->f_dentry->d_name.name;
const int len = file->f_dentry->d_name.len;
struct md_op_data *op_data;
- struct ptlrpc_request *req;
+ struct ptlrpc_request *req = NULL;
__u32 opc = LUSTRE_OPC_ANY;
int rc;
ENTRY;
if (IS_ERR(op_data))
RETURN(PTR_ERR(op_data));
+ op_data->op_data = lmm;
+ op_data->op_data_size = lmmsize;
+
itp->it_flags |= MDS_OPEN_BY_FID;
- rc = md_intent_lock(sbi->ll_md_exp, op_data, lmm, lmmsize, itp,
- 0 /*unused */, &req, ll_md_blocking_ast, 0);
+ rc = md_intent_lock(sbi->ll_md_exp, op_data, itp, &req,
+ &ll_md_blocking_ast, 0);
ll_finish_md_op_data(op_data);
if (rc == -ESTALE) {
/* reason for keep own exit path - don`t flood log
struct lookup_intent it = { .it_op = IT_OPEN };
struct ll_sb_info *sbi = ll_i2sbi(inode);
struct md_op_data *op_data;
- struct ptlrpc_request *req;
+ struct ptlrpc_request *req = NULL;
struct lustre_handle old_handle = { 0 };
struct obd_client_handle *och = NULL;
int rc;
it.it_flags = fmode | open_flags;
it.it_flags |= MDS_OPEN_LOCK | MDS_OPEN_BY_FID | MDS_OPEN_LEASE;
- rc = md_intent_lock(sbi->ll_md_exp, op_data, NULL, 0, &it, 0, &req,
- ll_md_blocking_lease_ast,
+ rc = md_intent_lock(sbi->ll_md_exp, op_data, &it, &req,
+ &ll_md_blocking_lease_ast,
/* LDLM_FL_NO_LRU: To not put the lease lock into LRU list, otherwise
* it can be cancelled which may mislead applications that the lease is
* broken;
* LDLM_FL_EXCL: Set this flag so that it won't be matched by normal
* open in ll_md_blocking_ast(). Otherwise as ll_md_blocking_lease_ast
* doesn't deal with openhandle, so normal openhandle will be leaked. */
- LDLM_FL_NO_LRU | LDLM_FL_EXCL);
+ LDLM_FL_NO_LRU | LDLM_FL_EXCL);
ll_finish_md_op_data(op_data);
ptlrpc_req_finished(req);
if (rc < 0)
if (it.d.lustre.it_lock_mode == 0 ||
it.d.lustre.it_lock_bits != MDS_INODELOCK_OPEN) {
/* open lock must return for lease */
- CERROR(DFID "lease granted but no open lock, %d/%Lu.\n",
+ CERROR(DFID "lease granted but no open lock, %d/"LPU64".\n",
PFID(ll_inode2fid(inode)), it.d.lustre.it_lock_mode,
it.d.lustre.it_lock_bits);
GOTO(out_close, rc = -EPROTO);
/**
* Called to make sure a portion of file has been written out.
- * if @local_only is not true, it will send OST_SYNC RPCs to ost.
+ * if @mode is not CL_FSYNC_LOCAL, it will send OST_SYNC RPCs to OST.
*
* Return how many pages have been written.
*/
int ll_fsync(struct file *file, int datasync)
{
struct dentry *dentry = file->f_dentry;
+ loff_t start = 0;
+ loff_t end = LLONG_MAX;
#else
int ll_fsync(struct file *file, struct dentry *dentry, int datasync)
{
+ loff_t start = 0;
+ loff_t end = LLONG_MAX;
#endif
struct inode *inode = dentry->d_inode;
struct ll_inode_info *lli = ll_i2info(inode);
if (S_ISREG(inode->i_mode)) {
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
- err = cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
- CL_FSYNC_ALL, 0);
+ err = cl_sync_file_range(inode, start, end, CL_FSYNC_ALL, 0);
if (rc == 0 && err < 0)
rc = err;
if (rc < 0)
struct md_op_data *op_data;
struct lustre_handle lockh = {0};
ldlm_policy_data_t flock = {{0}};
+ int fl_type = file_lock->fl_type;
__u64 flags = 0;
int rc;
int rc2 = 0;
if (file_lock->fl_lmops && file_lock->fl_lmops->lm_compare_owner)
flock.l_flock.owner = (unsigned long)file_lock->fl_pid;
- switch (file_lock->fl_type) {
+ switch (fl_type) {
case F_RDLCK:
einfo.ei_mode = LCK_PR;
break;
einfo.ei_mode = LCK_PW;
break;
default:
- CDEBUG(D_INFO, "Unknown fcntl lock type: %d\n",
- file_lock->fl_type);
+ CDEBUG(D_INFO, "Unknown fcntl lock type: %d\n", fl_type);
RETURN (-ENOTSUPP);
}
case F_GETLK64:
#endif
flags = LDLM_FL_TEST_LOCK;
- /* Save the old mode so that if the mode in the lock changes we
- * can decrement the appropriate reader or writer refcount. */
- file_lock->fl_type = einfo.ei_mode;
break;
default:
CERROR("unknown fcntl lock command: %d\n", cmd);
RETURN (-EINVAL);
}
+ /* Save the old mode so that if the mode in the lock changes we
+ * can decrement the appropriate reader or writer refcount. */
+ file_lock->fl_type = einfo.ei_mode;
+
op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
LUSTRE_OPC_ANY, NULL);
if (IS_ERR(op_data))
flock.l_flock.pid, flags, einfo.ei_mode,
flock.l_flock.start, flock.l_flock.end);
- rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL,
- op_data, &lockh, &flock, 0, NULL /* req */, flags);
+ rc = md_enqueue(sbi->ll_md_exp, &einfo, &flock, NULL, op_data, &lockh,
+ flags);
+
+ /* Restore the file lock type if not TEST lock. */
+ if (!(flags & LDLM_FL_TEST_LOCK))
+ file_lock->fl_type = fl_type;
if ((file_lock->fl_flags & FL_FLOCK) &&
(rc == 0 || file_lock->fl_type == F_UNLCK))
if (rc2 && file_lock->fl_type != F_UNLCK) {
einfo.ei_mode = LCK_NL;
- md_enqueue(sbi->ll_md_exp, &einfo, NULL,
- op_data, &lockh, &flock, 0, NULL /* req */, flags);
+ md_enqueue(sbi->ll_md_exp, &einfo, &flock, NULL, op_data,
+ &lockh, flags);
rc = rc2;
}
RETURN(PTR_ERR(op_data));
oit.it_create_mode |= M_CHECK_STALE;
- rc = md_intent_lock(exp, op_data, NULL, 0,
- /* we are not interested in name
- based lookup */
- &oit, 0, &req,
- ll_md_blocking_ast, 0);
+ rc = md_intent_lock(exp, op_data, &oit, &req,
+ &ll_md_blocking_ast, 0);
ll_finish_md_op_data(op_data);
oit.it_create_mode &= ~M_CHECK_STALE;
if (rc < 0) {
# endif
#endif
{
- int rc = 0;
- ENTRY;
+ int rc = 0;
+ struct ll_sb_info *sbi;
+ struct root_squash_info *squash;
+ struct cred *cred = NULL;
+ const struct cred *old_cred = NULL;
+ cfs_cap_t cap;
+ bool squash_id = false;
+ ENTRY;
#ifdef MAY_NOT_BLOCK
if (mask & MAY_NOT_BLOCK)
CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), inode mode %x mask %o\n",
PFID(ll_inode2fid(inode)), inode, inode->i_mode, mask);
- if (ll_i2sbi(inode)->ll_flags & LL_SBI_RMT_CLIENT)
- return lustre_check_remote_perm(inode, mask);
+ /* squash fsuid/fsgid if needed */
+ sbi = ll_i2sbi(inode);
+ squash = &sbi->ll_squash;
+ if (unlikely(squash->rsi_uid != 0 &&
+ current_fsuid() == 0 &&
+ !(sbi->ll_flags & LL_SBI_NOROOTSQUASH))) {
+ squash_id = true;
+ }
+ if (squash_id) {
+ CDEBUG(D_OTHER, "squash creds (%d:%d)=>(%d:%d)\n",
+ current_fsuid(), current_fsgid(),
+ squash->rsi_uid, squash->rsi_gid);
+
+ /* update current process's credentials
+ * and FS capability */
+ cred = prepare_creds();
+ if (cred == NULL)
+ RETURN(-ENOMEM);
+
+ cred->fsuid = squash->rsi_uid;
+ cred->fsgid = squash->rsi_gid;
+ for (cap = 0; cap < sizeof(cfs_cap_t) * 8; cap++) {
+ if ((1 << cap) & CFS_CAP_FS_MASK)
+ cap_lower(cred->cap_effective, cap);
+ }
+ old_cred = override_creds(cred);
+ }
- ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_INODE_PERM, 1);
- rc = ll_generic_permission(inode, mask, flags, ll_check_acl);
+ ll_stats_ops_tally(sbi, LPROC_LL_INODE_PERM, 1);
+
+ if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
+ rc = lustre_check_remote_perm(inode, mask);
+ else
+ rc = ll_generic_permission(inode, mask, flags, ll_check_acl);
+
+ /* restore current process's credentials and FS capability */
+ if (squash_id) {
+ revert_creds(old_cred);
+ put_cred(cred);
+ }
RETURN(rc);
}
/* dynamic ioctl number support routins */
static struct llioc_ctl_data {
struct rw_semaphore ioc_sem;
- cfs_list_t ioc_head;
+ struct list_head ioc_head;
} llioc = {
- __RWSEM_INITIALIZER(llioc.ioc_sem),
- CFS_LIST_HEAD_INIT(llioc.ioc_head)
+ __RWSEM_INITIALIZER(llioc.ioc_sem),
+ LIST_HEAD_INIT(llioc.ioc_head)
};
struct llioc_data {
- cfs_list_t iocd_list;
+ struct list_head iocd_list;
unsigned int iocd_size;
llioc_callback_t iocd_cb;
unsigned int iocd_count;
memcpy(in_data->iocd_cmd, cmd, sizeof(unsigned int) * count);
down_write(&llioc.ioc_sem);
- cfs_list_add_tail(&in_data->iocd_list, &llioc.ioc_head);
+ list_add_tail(&in_data->iocd_list, &llioc.ioc_head);
up_write(&llioc.ioc_sem);
RETURN(in_data);
return;
down_write(&llioc.ioc_sem);
- cfs_list_for_each_entry(tmp, &llioc.ioc_head, iocd_list) {
+ list_for_each_entry(tmp, &llioc.ioc_head, iocd_list) {
if (tmp == magic) {
unsigned int size = tmp->iocd_size;
- cfs_list_del(&tmp->iocd_list);
+ list_del(&tmp->iocd_list);
up_write(&llioc.ioc_sem);
OBD_FREE(tmp, size);
int rc = -EINVAL, i;
down_read(&llioc.ioc_sem);
- cfs_list_for_each_entry(data, &llioc.ioc_head, iocd_list) {
+ list_for_each_entry(data, &llioc.ioc_head, iocd_list) {
for (i = 0; i < data->iocd_count; i++) {
if (cmd != data->iocd_cmd[i])
continue;
struct ldlm_enqueue_info einfo = {
.ei_type = LDLM_IBITS,
.ei_mode = LCK_CR,
- .ei_cb_bl = ll_md_blocking_ast,
- .ei_cb_cp = ldlm_completion_ast,
+ .ei_cb_bl = &ll_md_blocking_ast,
+ .ei_cb_cp = &ldlm_completion_ast,
};
int rc;
ENTRY;
ll_get_fsname(inode->i_sb, NULL, 0),
PFID(&lli->lli_fid), inode);
- rc = md_enqueue(sbi->ll_md_exp, &einfo, &it, op_data, &lockh,
- NULL, 0, NULL, 0);
+ rc = md_enqueue(sbi->ll_md_exp, &einfo, NULL, &it, op_data, &lockh, 0);
if (it.d.lustre.it_data != NULL)
ptlrpc_req_finished(it.d.lustre.it_data);
it.d.lustre.it_data = NULL;