#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
#include <linux/lustre_compat25.h>
#endif
-
#include "llite_internal.h"
+#include <linux/obd_lov.h>
-static int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
- struct file *file)
+int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
+ struct file *file)
{
struct ll_file_data *fd = file->private_data;
struct ptlrpc_request *req = NULL;
struct obd_client_handle *och = &fd->fd_mds_och;
struct obdo obdo;
- int rc, valid;
+ int rc;
ENTRY;
- valid = OBD_MD_FLID;
+ /* clear group lock, if present */
+ if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
+ struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
+ fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
+ rc = ll_extent_unlock(fd, inode, lsm, LCK_GROUP,
+ &fd->fd_cwlockh);
+ }
- memset(&obdo, 0, sizeof(obdo));
obdo.o_id = inode->i_ino;
- obdo.o_mode = inode->i_mode;
- obdo.o_size = inode->i_size;
- obdo.o_blocks = inode->i_blocks;
+ obdo.o_valid = OBD_MD_FLID;
+ obdo_from_inode(&obdo, inode, OBD_MD_FLTYPE | OBD_MD_FLMODE |
+ OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
+ OBD_MD_FLATIME | OBD_MD_FLMTIME |
+ OBD_MD_FLCTIME);
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);
+ obdo.o_mds = ll_i2info(inode)->lli_mds;
+ rc = md_close(mdc_exp, &obdo, 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. */
inode->i_ino, rc);
}
if (rc == 0) {
- rc = ll_objects_destroy(req, file->f_dentry->d_inode);
+ rc = ll_objects_destroy(req, file->f_dentry->d_inode, 1);
if (rc)
CERROR("inode %lu ll_objects destroy: rc = %d\n",
inode->i_ino, rc);
}
- mdc_clear_open_replay_data(och);
+ mdc_clear_open_replay_data(mdc_exp, och);
ptlrpc_req_finished(req);
och->och_fh.cookie = DEAD_HANDLE_MAGIC;
file->private_data = NULL;
int rc;
ENTRY;
- CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
+ CDEBUG(D_VFSTRACE, "VFS Op:inode=%u/%lu/%u(%p)\n",
+ ll_i2info(inode)->lli_mds, inode->i_ino,
inode->i_generation, inode);
/* don't do anything for / */
ll_prepare_mdc_op_data(&data, parent->d_inode, NULL, name, len, O_RDWR);
- rc = mdc_enqueue(sbi->ll_mdc_exp, LDLM_PLAIN, itp, LCK_PR, &data,
- &lockh, lmm, lmmsize, ldlm_completion_ast,
- ll_mdc_blocking_ast, parent->d_inode);
- if (rc < 0)
+ rc = md_enqueue(sbi->ll_mdc_exp, LDLM_IBITS, itp, LCK_PR, &data,
+ &lockh, lmm, lmmsize, ldlm_completion_ast,
+ ll_mdc_blocking_ast, NULL);
+ if (rc == 0) {
+ if (itp->d.lustre.it_lock_mode)
+ memcpy(&itp->d.lustre.it_lock_handle,
+ &lockh, sizeof(lockh));
+ } else if (rc < 0) {
CERROR("lock enqueue: err: %d\n", rc);
+ }
+
RETURN(rc);
}
-static int ll_local_open(struct file *file, struct lookup_intent *it)
+int ll_local_open(struct file *file, struct lookup_intent *it)
{
struct ptlrpc_request *req = it->d.lustre.it_data;
struct ll_inode_info *lli = ll_i2info(file->f_dentry->d_inode);
+ struct obd_export *mdc_exp = ll_i2mdcexp(file->f_dentry->d_inode);
struct ll_file_data *fd;
struct mds_body *body;
ENTRY;
lli->lli_io_epoch = body->io_epoch;
- mdc_set_open_replay_data(&fd->fd_mds_och, it->d.lustre.it_data);
+ mdc_set_open_replay_data(mdc_exp, &fd->fd_mds_och, it->d.lustre.it_data);
RETURN(0);
}
int ll_file_open(struct inode *inode, struct file *file)
{
struct ll_inode_info *lli = ll_i2info(inode);
- struct lookup_intent *it;
+ struct lookup_intent *it, oit = { .it_op = IT_OPEN,
+ .it_flags = file->f_flags };
struct lov_stripe_md *lsm;
struct ptlrpc_request *req;
int rc = 0;
it = file->f_it;
- if (!it->d.lustre.it_disposition) {
- struct lookup_intent oit = { .it_op = IT_OPEN,
- .it_flags = file->f_flags };
+ if (!it || !it->d.lustre.it_disposition) {
it = &oit;
rc = ll_intent_file_open(file, NULL, 0, it);
if (rc)
memset(oa, 0, sizeof *oa);
oa->o_id = lsm->lsm_object_id;
+ oa->o_gr = lsm->lsm_object_gr;
oa->o_mode = S_IFREG;
oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
- OBD_MD_FLCTIME;
+ OBD_MD_FLCTIME | OBD_MD_FLGROUP;
set = ptlrpc_prep_set();
if (set == NULL) {
if (rc)
RETURN(rc);
- oa->o_valid &= (OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
+ oa->o_valid &= (OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
OBD_MD_FLCTIME | OBD_MD_FLSIZE);
RETURN(0);
}
ENTRY;
if (lsm->lsm_stripe_count == 1)
- RETURN(0);
+ GOTO(check, stripe = 0);
/* get our offset in the lov */
rc = obd_get_info(exp, sizeof(key), &key, &vallen, &stripe);
if (rc != 0) {
CERROR("obd_get_info: rc = %d\n", rc);
- LBUG();
+ RETURN(rc);
}
LASSERT(stripe < lsm->lsm_stripe_count);
+
+check:
+ if (lsm->lsm_oinfo[stripe].loi_id != lock->l_resource->lr_name.name[0]||
+ lsm->lsm_oinfo[stripe].loi_gr != lock->l_resource->lr_name.name[2]){
+ LDLM_ERROR(lock, "resource doesn't match object "LPU64"/"LPU64
+ " inode=%lu/%u (%p)\n",
+ lsm->lsm_oinfo[stripe].loi_id,
+ lsm->lsm_oinfo[stripe].loi_gr,
+ inode->i_ino, inode->i_generation, inode);
+ RETURN(-ELDLM_NO_LOCK_DATA);
+ }
+
RETURN(stripe);
}
*
* No one can dirty the extent until we've finished our work and they can
* enqueue another lock. The DLM protects us from ll_file_read/write here,
- * but other kernel actors could have pages locked. */
+ * but other kernel actors could have pages locked.
+ *
+ * Called with the DLM lock held. */
void ll_pgcache_remove_extent(struct inode *inode, struct lov_stripe_md *lsm,
struct ldlm_lock *lock, __u32 stripe)
{
- struct ldlm_extent *extent = &lock->l_policy_data.l_extent;
+ ldlm_policy_data_t tmpex;
unsigned long start, end, count, skip, i, j;
struct page *page;
- int rc, discard = lock->l_flags & LDLM_FL_DISCARD_DATA;
+ int rc, rc2, discard = lock->l_flags & LDLM_FL_DISCARD_DATA;
+ struct lustre_handle lockh;
ENTRY;
- CDEBUG(D_INODE, "obdo %lu inode %p ["LPU64"->"LPU64"] size: %llu\n",
- inode->i_ino, inode, extent->start, extent->end, inode->i_size);
+ memcpy(&tmpex, &lock->l_policy_data, sizeof(tmpex));
+ CDEBUG(D_INODE|D_PAGE, "inode %lu(%p) ["LPU64"->"LPU64"] size: %llu\n",
+ inode->i_ino, inode, tmpex.l_extent.start, tmpex.l_extent.end,
+ inode->i_size);
/* our locks are page granular thanks to osc_enqueue, we invalidate the
* whole page. */
- LASSERT((extent->start & ~PAGE_CACHE_MASK) == 0);
- LASSERT(((extent->end+1) & ~PAGE_CACHE_MASK) == 0);
+ LASSERT((tmpex.l_extent.start & ~PAGE_CACHE_MASK) == 0);
+ LASSERT(((tmpex.l_extent.end + 1) & ~PAGE_CACHE_MASK) == 0);
- start = extent->start >> PAGE_CACHE_SHIFT;
count = ~0;
skip = 0;
- end = (extent->end >> PAGE_CACHE_SHIFT) + 1;
- if ((end << PAGE_CACHE_SHIFT) < extent->end)
- end = ~0;
+ start = tmpex.l_extent.start >> PAGE_CACHE_SHIFT;
+ end = tmpex.l_extent.end >> PAGE_CACHE_SHIFT;
if (lsm->lsm_stripe_count > 1) {
count = lsm->lsm_stripe_size >> PAGE_CACHE_SHIFT;
skip = (lsm->lsm_stripe_count - 1) * count;
- start += (start/count * skip) + (stripe * count);
+ start += start/count * skip + stripe * count;
if (end != ~0)
- end += (end/count * skip) + (stripe * count);
- }
+ end += end/count * skip + stripe * count;
+ }
+ if (end < tmpex.l_extent.end >> PAGE_CACHE_SHIFT)
+ end = ~0;
i = (inode->i_size + PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT;
if (i < end)
end = i;
- CDEBUG(D_INODE, "walking page indices start: %lu j: %lu count: %lu "
- "skip: %lu end: %lu%s\n", start, start % count, count, skip, end,
- discard ? " (DISCARDING)" : "");
+ CDEBUG(D_INODE|D_PAGE, "walking page indices start: %lu j: %lu "
+ "count: %lu skip: %lu end: %lu%s\n", start, start % count,
+ count, skip, end, discard ? " (DISCARDING)" : "");
/* this is the simplistic implementation of page eviction at
* cancelation. It is careful to get races with other page
* lockers handled correctly. fixes from bug 20 will make it
* more efficient by associating locks with pages and with
* batching writeback under the lock explicitly. */
- for (i = start, j = start % count ; ; j++, i++) {
+ for (i = start, j = start % count; i <= end;
+ j++, i++, tmpex.l_extent.start += PAGE_CACHE_SIZE) {
if (j == count) {
+ CDEBUG(D_PAGE, "skip index %lu to %lu\n", i, i + skip);
i += skip;
j = 0;
+ if (i > end)
+ break;
}
- if (i >= end)
- break;
+ LASSERTF(tmpex.l_extent.start< lock->l_policy_data.l_extent.end,
+ LPU64" >= "LPU64" start %lu i %lu end %lu\n",
+ tmpex.l_extent.start, lock->l_policy_data.l_extent.end,
+ start, i, end);
- ll_pgcache_lock(inode->i_mapping);
- if (list_empty(&inode->i_mapping->dirty_pages) &&
- list_empty(&inode->i_mapping->clean_pages) &&
- list_empty(&inode->i_mapping->locked_pages)) {
- CDEBUG(D_INODE, "nothing left\n");
- ll_pgcache_unlock(inode->i_mapping);
+ if (!mapping_has_pages(inode->i_mapping)) {
+ CDEBUG(D_INODE|D_PAGE, "nothing left\n");
break;
}
- ll_pgcache_unlock(inode->i_mapping);
- conditional_schedule();
+ cond_resched();
page = find_get_page(inode->i_mapping, i);
if (page == NULL)
continue;
- LL_CDEBUG_PAGE(page, "locking page\n");
+ LL_CDEBUG_PAGE(D_PAGE, page, "lock page idx %lu ext "LPU64"\n",
+ i, tmpex.l_extent.start);
lock_page(page);
/* page->mapping to check with racing against teardown */
- if (page->mapping && PageDirty(page) && !discard) {
- ClearPageDirty(page);
- LL_CDEBUG_PAGE(page, "found dirty\n");
- ll_pgcache_lock(inode->i_mapping);
- list_del(&page->list);
- list_add(&page->list, &inode->i_mapping->locked_pages);
- ll_pgcache_unlock(inode->i_mapping);
-
+ if (!discard && clear_page_dirty_for_io(page)) {
rc = ll_call_writepage(inode, page);
if (rc != 0)
CERROR("writepage of page %p failed: %d\n",
lock_page(page);
}
- /* checking again to account for writeback's lock_page() */
- if (page->mapping != NULL) {
- LL_CDEBUG_PAGE(page, "truncating\n");
+ tmpex.l_extent.end = tmpex.l_extent.start + PAGE_CACHE_SIZE - 1;
+ /* check to see if another DLM lock covers this page */
+ rc2 = ldlm_lock_match(lock->l_resource->lr_namespace,
+ LDLM_FL_BLOCK_GRANTED|LDLM_FL_CBPENDING |
+ LDLM_FL_TEST_LOCK,
+ &lock->l_resource->lr_name, LDLM_EXTENT,
+ &tmpex, LCK_PR | LCK_PW, &lockh);
+ if (rc2 == 0 && page->mapping != NULL) {
+ // checking again to account for writeback's lock_page()
+ LL_CDEBUG_PAGE(D_PAGE, page, "truncating\n");
ll_truncate_complete_page(page);
}
unlock_page(page);
page_cache_release(page);
}
+ LASSERTF(tmpex.l_extent.start <=
+ (lock->l_policy_data.l_extent.end == ~0ULL ? ~0ULL :
+ lock->l_policy_data.l_extent.end + 1),
+ "loop too long "LPU64" > "LPU64" start %lu i %lu end %lu\n",
+ tmpex.l_extent.start, lock->l_policy_data.l_extent.end,
+ start, i, end);
EXIT;
}
CERROR("ldlm_cli_cancel failed: %d\n", rc);
break;
case LDLM_CB_CANCELING: {
- struct inode *inode = ll_inode_from_lock(lock);
+ struct inode *inode;
struct ll_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 = ll_inode_from_lock(lock);
if (inode == NULL)
RETURN(0);
lli = ll_i2info(inode);
lsm = lli->lli_smd;
stripe = ll_lock_to_stripe_offset(inode, lock);
+ if (stripe < 0)
+ goto iput;
ll_pgcache_remove_extent(inode, lsm, lock, stripe);
down(&inode->i_sem);
kms = ldlm_extent_shift_kms(lock,
lsm->lsm_oinfo[stripe].loi_kms);
+
if (lsm->lsm_oinfo[stripe].loi_kms != kms)
LDLM_DEBUG(lock, "updating kms from "LPU64" to "LPU64,
lsm->lsm_oinfo[stripe].loi_kms, kms);
LDLM_DEBUG(lock, "client-side async enqueue: granted/glimpsed");
stripe = ll_lock_to_stripe_offset(inode, lock);
+ if (stripe < 0)
+ goto iput;
if (lock->l_lvb_len) {
struct lov_stripe_md *lsm = lli->lli_smd;
up(&inode->i_sem);
}
+iput:
iput(inode);
wake_up(&lock->l_waitq);
}
#endif
-/* This function is a disaster. I hate the LOV. */
static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp)
{
struct ptlrpc_request *req = reqp;
struct inode *inode = ll_inode_from_lock(lock);
- struct obd_export *exp;
struct ll_inode_info *lli;
struct ost_lvb *lvb;
- struct {
- int stripe_number;
- __u64 size;
- struct lov_stripe_md *lsm;
- } data;
- __u32 vallen = sizeof(data);
- int rc, size = sizeof(*lvb);
+ int rc, size = sizeof(*lvb), stripe;
ENTRY;
if (inode == NULL)
- RETURN(0);
+ GOTO(out, rc = -ELDLM_NO_LOCK_DATA);
lli = ll_i2info(inode);
if (lli == NULL)
- goto iput;
+ GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
if (lli->lli_smd == NULL)
- goto iput;
- exp = ll_i2obdexp(inode);
+ 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)
- data.stripe_number = ll_lock_to_stripe_offset(inode, lock);
- else
- data.stripe_number = 0;
-
- data.size = inode->i_size;
- data.lsm = lli->lli_smd;
-
- rc = obd_get_info(exp, strlen("size_to_stripe"), "size_to_stripe",
- &vallen, &data);
- if (rc != 0) {
- CERROR("obd_get_info: rc = %d\n", rc);
- LBUG();
- }
-
- LDLM_DEBUG(lock, "i_size: %Lu -> stripe number %d -> size %Lu",
- inode->i_size, data.stripe_number, data.size);
+ stripe = ll_lock_to_stripe_offset(inode, lock);
+ if (stripe < 0)
+ GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
rc = lustre_pack_reply(req, 1, &size, NULL);
if (rc) {
CERROR("lustre_pack_reply: %d\n", rc);
- goto iput;
+ GOTO(iput, rc);
}
lvb = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*lvb));
- lvb->lvb_size = data.size;
- ptlrpc_reply(req);
+ lvb->lvb_size = lli->lli_smd->lsm_oinfo[stripe].loi_kms;
+ LDLM_DEBUG(lock, "i_size: %llu -> stripe number %u -> kms "LPU64,
+ inode->i_size, stripe, lvb->lvb_size);
+ GOTO(iput, 0);
iput:
iput(inode);
- RETURN(0);
+
+ 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, 0, NULL, NULL);
+
+ req->rq_status = rc;
+ return rc;
}
__u64 lov_merge_size(struct lov_stripe_md *lsm, int kms);
+__u64 lov_merge_blocks(struct lov_stripe_md *lsm);
__u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time);
/* NB: lov_merge_size will prefer locally cached writes if they extend the
struct ll_inode_info *lli = ll_i2info(inode);
struct ll_sb_info *sbi = ll_i2sbi(inode);
ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
- struct lustre_handle lockh;
+ struct lustre_handle lockh = { 0 };
int rc, flags = LDLM_FL_HAS_INTENT;
ENTRY;
LCK_PR, &flags, ll_extent_lock_callback,
ldlm_completion_ast, ll_glimpse_callback, inode,
sizeof(*lvb), lustre_swab_ost_lvb, &lockh);
- if (rc > 0)
- RETURN(-EIO);
+ if (rc != 0) {
+ CERROR("obd_enqueue returned rc %d, returning -EIO\n", rc);
+ RETURN(rc > 0 ? -EIO : rc);
+ }
lvb->lvb_size = lov_merge_size(lli->lli_smd, 0);
+ inode->i_blocks = lov_merge_blocks(lli->lli_smd);
//inode->i_mtime = lov_merge_mtime(lli->lli_smd, inode->i_mtime);
- CDEBUG(D_DLMTRACE, "glimpse: size: "LPU64"\n", lvb->lvb_size);
+ CDEBUG(D_DLMTRACE, "glimpse: size: "LPU64", blocks: "LPU64"\n",
+ lvb->lvb_size, lvb->lvb_blocks);
obd_cancel(sbi->ll_osc_exp, lli->lli_smd, LCK_PR, &lockh);
struct lov_stripe_md *lsm = lli->lli_smd;
struct lustre_handle lockh = { 0 };
ldlm_policy_data_t policy;
- ldlm_error_t err;
+ int rc;
ssize_t retval;
__u64 kms;
ENTRY;
policy.l_extent.start = *ppos;
policy.l_extent.end = *ppos + count - 1;
- err = ll_extent_lock(fd, inode, lsm, LCK_PR, &policy, &lockh, 0);
- if (err != ELDLM_OK)
- RETURN(err);
+ rc = ll_extent_lock(fd, inode, lsm, LCK_PR, &policy, &lockh,
+ (filp->f_flags & O_NONBLOCK) ?
+ LDLM_FL_BLOCK_NOWAIT: 0);
+ if (rc != 0)
+ RETURN(rc);
kms = lov_merge_size(lsm, 1);
- if (policy.l_extent.end > kms) {
+ if (*ppos + count - 1 > kms) {
/* A glimpse is necessary to determine whether we return a short
* read or some zeroes at the end of the buffer */
struct ost_lvb lvb;
inode->i_size = kms;
}
- CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld, i_size "
- LPU64"\n", inode->i_ino, count, *ppos, inode->i_size);
+ CDEBUG(D_INFO, "Read ino %lu, "LPSZ" bytes, offset %lld, i_size %llu\n",
+ inode->i_ino, count, *ppos, inode->i_size);
/* turn off the kernel's read-ahead */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
struct lustre_handle lockh = { 0 };
ldlm_policy_data_t policy;
loff_t maxbytes = ll_file_maxbytes(inode);
- ldlm_error_t err;
ssize_t retval;
+ int nonblock = 0, rc;
ENTRY;
+ if (file->f_flags & O_NONBLOCK)
+ nonblock = LDLM_FL_BLOCK_NOWAIT;
CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),size="LPSZ",offset=%Ld\n",
inode->i_ino, inode->i_generation, inode, count, *ppos);
policy.l_extent.end = *ppos + count - 1;
}
- err = ll_extent_lock(fd, inode, lsm, LCK_PW, &policy, &lockh, 0);
- if (err != ELDLM_OK)
- RETURN(err);
+ rc = ll_extent_lock(fd, inode, lsm, LCK_PW, &policy, &lockh, nonblock);
+ if (rc != 0)
+ RETURN(rc);
/* this is ok, g_f_w will overwrite this under i_sem if it races
* with a local truncate, it just makes our maxbyte checking easier */
retval = generic_file_write(file, buf, count, ppos);
out:
- /* XXX errors? */
- lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_WRITE_BYTES,
- retval);
ll_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
+ lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_WRITE_BYTES,
+ retval > 0 ? retval : 0);
RETURN(retval);
}
if (!capable (CAP_SYS_ADMIN))
RETURN(-EPERM);
- rc = copy_from_user(&ucreatp, (struct ll_recreate_obj *)arg,
+ rc = copy_from_user(&ucreatp, (struct ll_recreate_obj *)arg,
sizeof(struct ll_recreate_obj));
if (rc) {
RETURN(-EFAULT);
RETURN(-ENOMEM);
}
- oa->o_id = ucreatp.lrc_id;
+ oa->o_id = ucreatp.lrc_id;
oa->o_nlink = ucreatp.lrc_ost_idx;
- oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
+ oa->o_gr = ucreatp.lrc_group;
+ oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLFLAGS;
oa->o_flags |= OBD_FL_RECREATE_OBJS;
obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
OBD_MD_FLMTIME | OBD_MD_FLCTIME);
}
static int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
- int flags, struct lov_user_md *lum, int lum_size)
+ int flags, struct lov_user_md *lum,
+ int lum_size)
{
struct ll_inode_info *lli = ll_i2info(inode);
struct file *f;
if (rc < 0)
GOTO(out, rc);
- rc = mdc_req2lustre_md(req, 1, exp, &md);
+ rc = mdc_req2lustre_md(ll_i2mdcexp(inode), req, 1, exp, &md);
if (rc)
GOTO(out, rc);
- ll_update_inode(f->f_dentry->d_inode, md.body, md.lsm);
+ ll_update_inode(f->f_dentry->d_inode, &md);
rc = ll_local_open(f, &oit);
if (rc)
{
int flags = MDS_OPEN_HAS_OBJS | FMODE_WRITE;
struct lov_user_md *lump;
- int lum_size = sizeof(struct lov_user_md) +
+ int lum_size = sizeof(struct lov_user_md) +
sizeof(struct lov_user_ost_data);
int rc;
ENTRY;
if (lump == NULL) {
RETURN(-ENOMEM);
}
- rc = copy_from_user(lump, (struct lov_user_md *)arg,
- lum_size);
+ rc = copy_from_user(lump, (struct lov_user_md *)arg, lum_size);
if (rc) {
OBD_FREE(lump, lum_size);
RETURN(-EFAULT);
(void *)arg);
}
+static int ll_get_grouplock(struct inode *inode, struct file *file,
+ unsigned long arg)
+{
+ struct ll_file_data *fd = file->private_data;
+ ldlm_policy_data_t policy = { .l_extent = { .start = 0,
+ .end = OBD_OBJECT_EOF}};
+ struct lustre_handle lockh = { 0 };
+ struct ll_inode_info *lli = ll_i2info(inode);
+ struct lov_stripe_md *lsm = lli->lli_smd;
+ int flags = 0, rc;
+ ENTRY;
+
+ if (fd->fd_flags & LL_FILE_GROUP_LOCKED) {
+ RETURN(-EINVAL);
+ }
+
+ policy.l_extent.gid = arg;
+ if (file->f_flags & O_NONBLOCK)
+ flags = LDLM_FL_BLOCK_NOWAIT;
+
+ rc = ll_extent_lock(fd, inode, lsm, LCK_GROUP, &policy, &lockh, flags);
+ if (rc != 0)
+ RETURN(rc);
+
+ fd->fd_flags |= LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK;
+ fd->fd_gid = arg;
+ memcpy(&fd->fd_cwlockh, &lockh, sizeof(lockh));
+
+ RETURN(0);
+}
+
+static int ll_put_grouplock(struct inode *inode, struct file *file,
+ unsigned long arg)
+{
+ struct ll_file_data *fd = file->private_data;
+ struct ll_inode_info *lli = ll_i2info(inode);
+ struct lov_stripe_md *lsm = lli->lli_smd;
+ int rc;
+ ENTRY;
+
+ if (!(fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
+ /* Ugh, it's already unlocked. */
+ RETURN(-EINVAL);
+ }
+
+ if (fd->fd_gid != arg) /* Ugh? Unlocking with different gid? */
+ RETURN(-EINVAL);
+
+ fd->fd_flags &= ~(LL_FILE_GROUP_LOCKED|LL_FILE_IGNORE_LOCK);
+
+ rc = ll_extent_unlock(fd, inode, lsm, LCK_GROUP, &fd->fd_cwlockh);
+ if (rc)
+ RETURN(rc);
+
+ fd->fd_gid = 0;
+ memset(&fd->fd_cwlockh, 0, sizeof(fd->fd_cwlockh));
+
+ RETURN(0);
+}
+
int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg)
{
case LL_IOC_LOV_SETSTRIPE:
RETURN(ll_lov_setstripe(inode, file, arg));
case LL_IOC_LOV_SETEA:
- RETURN( ll_lov_setea(inode, file, arg) );
+ RETURN(ll_lov_setea(inode, file, arg));
case LL_IOC_LOV_GETSTRIPE:
RETURN(ll_lov_getstripe(inode, arg));
case LL_IOC_RECREATE_OBJ:
case EXT3_IOC_GETFLAGS:
case EXT3_IOC_SETFLAGS:
RETURN( ll_iocontrol(inode, file, cmd, arg) );
+ case LL_IOC_GROUP_LOCK:
+ RETURN(ll_get_grouplock(inode, file, arg));
+ case LL_IOC_GROUP_UNLOCK:
+ RETURN(ll_put_grouplock(inode, file, arg));
/* We need to special case any other ioctls we want to handle,
* to send them to the MDS/OST as appropriate and to properly
* network encode the arg field.
lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_LLSEEK);
if (origin == 2) { /* SEEK_END */
- ldlm_error_t err;
+ int nonblock = 0, rc;
ldlm_policy_data_t policy = { .l_extent = {0, OBD_OBJECT_EOF }};
- err = ll_extent_lock(fd, inode, lsm, LCK_PR, &policy, &lockh,0);
- if (err != ELDLM_OK)
- RETURN(err);
+
+ if (file->f_flags & O_NONBLOCK)
+ nonblock = LDLM_FL_BLOCK_NOWAIT;
+
+ rc = ll_extent_lock(fd, inode, lsm, LCK_PR, &policy, &lockh,
+ nonblock);
+ if (rc != 0)
+ RETURN(rc);
offset += inode->i_size;
} else if (origin == 1) { /* SEEK_CUR */
rc = filemap_fdatawait(inode->i_mapping);
ll_inode2fid(&fid, inode);
- err = mdc_sync(ll_i2sbi(inode)->ll_mdc_exp, &fid, &req);
+ err = md_sync(ll_i2sbi(inode)->ll_mdc_exp, &fid, &req);
if (!rc)
rc = err;
if (!err)
RETURN(rc ? rc : -ENOMEM);
oa->o_id = lsm->lsm_object_id;
+ oa->o_gr = lsm->lsm_object_gr;
oa->o_valid = OBD_MD_FLID;
obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
- OBD_MD_FLMTIME | OBD_MD_FLCTIME);
+ OBD_MD_FLMTIME | OBD_MD_FLCTIME |
+ OBD_MD_FLGROUP);
err = obd_sync(ll_i2sbi(inode)->ll_osc_exp, oa, lsm,
0, OBD_OBJECT_EOF);
switch (cmd) {
case F_SETLKW:
+#ifdef F_SETLKW64
+ case F_SETLKW64:
+#endif
flags = 0;
break;
case F_SETLK:
+#ifdef F_SETLK64
+ case F_SETLK64:
+#endif
flags = LDLM_FL_BLOCK_NOWAIT;
break;
case F_GETLK:
+#ifdef F_GETLK64
+ 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. */
LBUG();
}
- CDEBUG(D_DLMTRACE, "inode=%lu, pid=%u, flags=%#x, mode=%u, "
+ CDEBUG(D_DLMTRACE, "inode=%lu, pid="LPU64", flags=%#x, mode=%u, "
"start="LPU64", end="LPU64"\n", inode->i_ino, flock.l_flock.pid,
flags, mode, flock.l_flock.start, flock.l_flock.end);
- obddev = sbi->ll_mdc_exp->exp_obd;
- rc = ldlm_cli_enqueue(sbi->ll_mdc_exp, NULL, obddev->obd_namespace,
+ obddev = md_get_real_obd(sbi->ll_mdc_exp, NULL, 0);
+ rc = ldlm_cli_enqueue(obddev->obd_self_export, NULL,
+ obddev->obd_namespace,
res_id, LDLM_FLOCK, &flock, mode, &flags,
NULL, ldlm_flock_completion_ast, NULL, file_lock,
NULL, 0, NULL, &lockh);
RETURN(rc);
}
-static int ll_have_md_lock(struct dentry *de)
-{
- struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
- struct lustre_handle lockh;
- struct ldlm_res_id res_id = { .name = {0} };
- struct obd_device *obddev;
- int flags;
- ENTRY;
-
- if (!de->d_inode)
- RETURN(0);
-
- obddev = sbi->ll_mdc_exp->exp_obd;
- res_id.name[0] = de->d_inode->i_ino;
- res_id.name[1] = de->d_inode->i_generation;
-
- CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
-
- flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
- if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
- NULL, LCK_PR, &lockh)) {
- ldlm_lock_decref(&lockh, LCK_PR);
- RETURN(1);
- }
-
- if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
- NULL, LCK_PW, &lockh)) {
- ldlm_lock_decref(&lockh, LCK_PW);
- RETURN(1);
- }
- RETURN(0);
-}
-
int ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it)
{
struct inode *inode = dentry->d_inode;
struct ll_inode_info *lli;
struct lov_stripe_md *lsm;
+ struct ll_fid fid;
+ int rc;
ENTRY;
if (!inode) {
CERROR("REPORT THIS LINE TO PETER\n");
RETURN(0);
}
+ ll_inode2fid(&fid, inode);
lli = ll_i2info(inode);
- CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s\n",
- inode->i_ino, inode->i_generation, inode, dentry->d_name.name);
+ CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s,intent=%s\n",
+ inode->i_ino, inode->i_generation, inode, dentry->d_name.name,
+ LL_IT2STR(it));
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_REVALIDATE);
#endif
- if (!ll_have_md_lock(dentry)) {
+ if (!md_valid_attrs(ll_i2mdcexp(inode), &fid)) {
struct ptlrpc_request *req = NULL;
struct ll_sb_info *sbi = ll_i2sbi(dentry->d_inode);
struct ll_fid fid;
unsigned long valid = 0;
- int rc, ealen = 0;
+ int ealen = 0;
if (S_ISREG(inode->i_mode)) {
ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
valid |= OBD_MD_FLEASIZE;
}
ll_inode2fid(&fid, inode);
- rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
+ rc = md_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
if (rc) {
CERROR("failure %d inode %lu\n", rc, inode->i_ino);
RETURN(-abs(rc));
}
- rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, 0, NULL);
+ rc = ll_prep_inode(sbi->ll_osc_exp, sbi->ll_mdc_exp,
+ &inode, req, 0, NULL);
if (rc) {
ptlrpc_req_finished(req);
RETURN(rc);
* the file */
{
struct ost_lvb lvb;
- ldlm_error_t err;
- err = ll_glimpse_size(inode, &lvb);
+ rc = ll_glimpse_size(inode, &lvb);
inode->i_size = lvb.lvb_size;
}
- RETURN(0);
+ RETURN(rc);
}
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
#endif
struct file_operations ll_file_operations = {
- read: ll_file_read,
- write: ll_file_write,
- ioctl: ll_file_ioctl,
- open: ll_file_open,
- release: ll_file_release,
- mmap: generic_file_mmap,
- llseek: ll_file_seek,
- fsync: ll_fsync,
- //lock: ll_file_flock
+ .read = ll_file_read,
+ .write = ll_file_write,
+ .ioctl = ll_file_ioctl,
+ .open = ll_file_open,
+ .release = ll_file_release,
+ .mmap = generic_file_mmap,
+ .llseek = ll_file_seek,
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
+ .sendfile = generic_file_sendfile,
+#endif
+ .fsync = ll_fsync,
+ .lock = ll_file_flock
};
struct inode_operations ll_file_inode_operations = {
- setattr_raw: ll_setattr_raw,
- setattr: ll_setattr,
- truncate: ll_truncate,
+ .setattr_raw = ll_setattr_raw,
+ .setattr = ll_setattr,
+ .truncate = ll_truncate,
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
- getattr_it: ll_getattr,
+ .getattr_it = ll_getattr,
#else
- revalidate_it: ll_inode_revalidate_it,
+ .revalidate_it = ll_inode_revalidate_it,
#endif
};
-struct inode_operations ll_special_inode_operations = {
- setattr_raw: ll_setattr_raw,
- setattr: ll_setattr,
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
- getattr_it: ll_getattr,
-#else
- revalidate_it: ll_inode_revalidate_it,
-#endif
-};