1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
30 #include <sys/types.h>
31 #include <sys/queue.h>
41 #include "llite_lib.h"
43 static int llu_lock_to_stripe_offset(struct inode *inode, struct ldlm_lock *lock)
45 struct llu_inode_info *lli = llu_i2info(inode);
46 struct lov_stripe_md *lsm = lli->lli_smd;
47 struct obd_export *exp = llu_i2obdexp(inode);
50 struct ldlm_lock *lock;
51 struct lov_stripe_md *lsm;
52 } key = { .name = "lock_to_stripe", .lock = lock, .lsm = lsm };
53 __u32 stripe, vallen = sizeof(stripe);
57 if (lsm->lsm_stripe_count == 1)
60 /* get our offset in the lov */
61 rc = obd_get_info(exp, sizeof(key), &key, &vallen, &stripe);
63 CERROR("obd_get_info: rc = %d\n", rc);
66 LASSERT(stripe < lsm->lsm_stripe_count);
70 static int llu_extent_lock_callback(struct ldlm_lock *lock,
71 struct ldlm_lock_desc *new, void *data,
74 struct lustre_handle lockh = { 0 };
79 if ((unsigned long)data > 0 && (unsigned long)data < 0x1000) {
80 LDLM_ERROR(lock, "cancelling lock with bad data %p", data);
85 case LDLM_CB_BLOCKING:
86 ldlm_lock2handle(lock, &lockh);
87 rc = ldlm_cli_cancel(&lockh);
89 CERROR("ldlm_cli_cancel failed: %d\n", rc);
91 case LDLM_CB_CANCELING: {
92 struct inode *inode = llu_inode_from_lock(lock);
93 struct llu_inode_info *lli;
94 struct lov_stripe_md *lsm;
100 lli= llu_i2info(inode);
107 stripe = llu_lock_to_stripe_offset(inode, lock);
108 kms = ldlm_extent_shift_kms(lock,
109 lsm->lsm_oinfo[stripe].loi_kms);
110 if (lsm->lsm_oinfo[stripe].loi_kms != kms)
111 LDLM_DEBUG(lock, "updating kms from "LPU64" to "LPU64,
112 lsm->lsm_oinfo[stripe].loi_kms, kms);
113 lsm->lsm_oinfo[stripe].loi_kms = kms;
125 static int llu_glimpse_callback(struct ldlm_lock *lock, void *reqp)
127 struct ptlrpc_request *req = reqp;
128 struct inode *inode = llu_inode_from_lock(lock);
129 struct obd_export *exp;
130 struct llu_inode_info *lli;
135 struct lov_stripe_md *lsm;
137 __u32 vallen = sizeof(data);
138 int rc, size = sizeof(*lvb);
143 lli = llu_i2info(inode);
146 if (lli->lli_smd == NULL)
148 exp = llu_i2obdexp(inode);
150 /* First, find out which stripe index this lock corresponds to. */
151 if (lli->lli_smd->lsm_stripe_count > 1)
152 data.stripe_number = llu_lock_to_stripe_offset(inode, lock);
154 data.stripe_number = 0;
156 data.size = lli->lli_st_size;
157 data.lsm = lli->lli_smd;
159 rc = obd_get_info(exp, strlen("size_to_stripe"), "size_to_stripe",
162 CERROR("obd_get_info: rc = %d\n", rc);
166 LDLM_DEBUG(lock, "i_size: %Lu -> stripe number %d -> size %Lu",
167 lli->lli_st_size, data.stripe_number, data.size);
169 rc = lustre_pack_reply(req, 1, &size, NULL);
171 CERROR("lustre_pack_reply: %d\n", rc);
175 lvb = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*lvb));
176 lvb->lvb_size = data.size;
184 __u64 lov_merge_size(struct lov_stripe_md *lsm, int kms);
185 __u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time);
187 /* NB: lov_merge_size will prefer locally cached writes if they extend the
188 * file (because it prefers KMS over RSS when larger) */
189 int llu_glimpse_size(struct inode *inode, struct ost_lvb *lvb)
191 struct llu_inode_info *lli = llu_i2info(inode);
192 struct llu_sb_info *sbi = llu_i2sbi(inode);
193 ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
194 struct lustre_handle lockh;
195 int rc, flags = LDLM_FL_HAS_INTENT;
198 CDEBUG(D_DLMTRACE, "Glimpsing inode %lu\n", lli->lli_st_ino);
200 rc = obd_enqueue(sbi->ll_osc_exp, lli->lli_smd, LDLM_EXTENT, &policy,
201 LCK_PR, &flags, llu_extent_lock_callback,
202 ldlm_completion_ast, llu_glimpse_callback, inode,
203 sizeof(*lvb), lustre_swab_ost_lvb, &lockh);
207 lvb->lvb_size = lov_merge_size(lli->lli_smd, 0);
208 //inode->i_mtime = lov_merge_mtime(lli->lli_smd, inode->i_mtime);
210 CDEBUG(D_DLMTRACE, "glimpse: size: "LPU64"\n", lvb->lvb_size);
212 obd_cancel(sbi->ll_osc_exp, lli->lli_smd, LCK_PR, &lockh);
217 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
218 struct lov_stripe_md *lsm, int mode,
219 ldlm_policy_data_t *policy, struct lustre_handle *lockh,
222 struct llu_sb_info *sbi = llu_i2sbi(inode);
223 struct llu_inode_info *lli = llu_i2info(inode);
227 LASSERT(lockh->cookie == 0);
229 /* XXX phil: can we do this? won't it screw the file size up? */
230 if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
231 (sbi->ll_flags & LL_SBI_NOLCK))
234 CDEBUG(D_DLMTRACE, "Locking inode %lu, start "LPU64" end "LPU64"\n",
235 lli->lli_st_ino, policy->l_extent.start, policy->l_extent.end);
237 rc = obd_enqueue(sbi->ll_osc_exp, lsm, LDLM_EXTENT, policy, mode,
238 &ast_flags, llu_extent_lock_callback,
239 ldlm_completion_ast, llu_glimpse_callback, inode,
240 sizeof(struct ost_lvb), lustre_swab_ost_lvb, lockh);
244 if (policy->l_extent.start == 0 &&
245 policy->l_extent.end == OBD_OBJECT_EOF)
246 lli->lli_st_size = lov_merge_size(lsm, 1);
248 //inode->i_mtime = lov_merge_mtime(lsm, inode->i_mtime);
254 int llu_extent_lock_no_validate(struct ll_file_data *fd,
256 struct lov_stripe_md *lsm,
258 struct ldlm_extent *extent,
259 struct lustre_handle *lockh,
262 struct llu_sb_info *sbi = llu_i2sbi(inode);
263 struct llu_inode_info *lli = llu_i2info(inode);
267 LASSERT(lockh->cookie == 0);
269 /* XXX phil: can we do this? won't it screw the file size up? */
270 if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
271 (sbi->ll_flags & LL_SBI_NOLCK))
274 CDEBUG(D_DLMTRACE, "Locking inode %lu, start "LPU64" end "LPU64"\n",
275 lli->lli_st_ino, extent->start, extent->end);
277 rc = obd_enqueue(sbi->ll_osc_exp, lsm, NULL, LDLM_EXTENT, extent,
278 sizeof(extent), mode, &ast_flags,
279 llu_extent_lock_callback, inode, lockh);
285 * this grabs a lock and manually implements behaviour that makes it look like
286 * the OST is returning the file size with each lock acquisition.
288 int llu_extent_lock(struct ll_file_data *fd, struct inode *inode,
289 struct lov_stripe_md *lsm, int mode,
290 struct ldlm_extent *extent, struct lustre_handle *lockh)
292 struct llu_inode_info *lli = llu_i2info(inode);
293 struct obd_export *exp = llu_i2obdexp(inode);
294 struct ldlm_extent size_lock;
295 struct lustre_handle match_lockh = {0};
296 int flags, rc, matched;
299 rc = llu_extent_lock_no_validate(fd, inode, lsm, mode, extent, lockh, 0);
303 if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
306 rc = llu_inode_getattr(inode, lsm);
308 llu_extent_unlock(fd, inode, lsm, mode, lockh);
312 size_lock.start = lli->lli_st_size;
313 size_lock.end = OBD_OBJECT_EOF;
315 /* XXX I bet we should be checking the lock ignore flags.. */
316 flags = LDLM_FL_CBPENDING | LDLM_FL_BLOCK_GRANTED;
317 matched = obd_match(exp, lsm, LDLM_EXTENT, &size_lock,
318 sizeof(size_lock), LCK_PR, &flags, inode,
321 /* hey, alright, we hold a size lock that covers the size we
322 * just found, its not going to change for a while.. */
324 set_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags);
325 obd_cancel(exp, lsm, LCK_PR, &match_lockh);
332 int llu_extent_unlock(struct ll_file_data *fd, struct inode *inode,
333 struct lov_stripe_md *lsm, int mode,
334 struct lustre_handle *lockh)
336 struct llu_sb_info *sbi = llu_i2sbi(inode);
340 /* XXX phil: can we do this? won't it screw the file size up? */
341 if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
342 (sbi->ll_flags & LL_SBI_NOLCK))
345 rc = obd_cancel(sbi->ll_osc_exp, lsm, mode, lockh);
350 #define LLAP_MAGIC 12346789
352 struct ll_async_page {
356 struct page *llap_page;
357 struct inode *llap_inode;
360 static struct ll_async_page *llap_from_cookie(void *cookie)
362 struct ll_async_page *llap = cookie;
363 if (llap->llap_magic != LLAP_MAGIC)
364 return ERR_PTR(-EINVAL);
368 static void llu_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
370 struct ll_async_page *llap;
372 struct lov_stripe_md *lsm;
373 obd_flag valid_flags;
376 llap = llap_from_cookie(data);
382 inode = llap->llap_inode;
383 lsm = llu_i2info(inode)->lli_smd;
385 oa->o_id = lsm->lsm_object_id;
386 oa->o_valid = OBD_MD_FLID;
387 valid_flags = OBD_MD_FLTYPE | OBD_MD_FLATIME;
388 if (cmd == OBD_BRW_WRITE)
389 valid_flags |= OBD_MD_FLMTIME | OBD_MD_FLCTIME;
391 obdo_from_inode(oa, inode, valid_flags);
395 /* called for each page in a completed rpc.*/
396 static void llu_ap_completion(void *data, int cmd, int rc)
398 struct ll_async_page *llap;
401 llap = llap_from_cookie(data);
407 llap->llap_queued = 0;
408 page = llap->llap_page;
411 if (cmd == OBD_BRW_WRITE)
412 CERROR("writeback error on page %p index %ld: %d\n",
413 page, page->index, rc);
418 static struct obd_async_page_ops llu_async_page_ops = {
419 .ap_make_ready = NULL,
420 .ap_refresh_count = NULL,
421 .ap_fill_obdo = llu_ap_fill_obdo,
422 .ap_completion = llu_ap_completion,
426 struct llu_sysio_cookie* get_sysio_cookie(struct inode *inode, int maxpages)
428 struct llu_sysio_cookie *cookie;
431 OBD_ALLOC(cookie, LLU_SYSIO_COOKIE_SIZE(maxpages));
436 cookie->lsc_inode = inode;
437 cookie->lsc_maxpages = maxpages;
438 cookie->lsc_llap = (struct ll_async_page *)(cookie + 1);
439 cookie->lsc_pages = (struct page *) (cookie->lsc_llap + maxpages);
441 rc = oig_init(&cookie->lsc_oig);
443 OBD_FREE(cookie, LLU_SYSIO_COOKIE_SIZE(maxpages));
452 void put_sysio_cookie(struct llu_sysio_cookie *cookie)
454 struct lov_stripe_md *lsm = llu_i2info(cookie->lsc_inode)->lli_smd;
455 struct obd_export *exp = llu_i2obdexp(cookie->lsc_inode);
456 struct ll_async_page *llap = cookie->lsc_llap;
457 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
458 struct page *pages = cookie->lsc_pages;
462 for (i = 0; i< cookie->lsc_maxpages; i++) {
463 if (llap[i].llap_cookie)
464 obd_teardown_async_page(exp, lsm, NULL,
465 llap[i].llap_cookie);
466 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
467 if (pages[i]._managed) {
469 pages[i]._managed = 0;
474 I_RELE(cookie->lsc_inode);
476 oig_release(cookie->lsc_oig);
477 OBD_FREE(cookie, LLU_SYSIO_COOKIE_SIZE(cookie->lsc_maxpages));
480 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
481 /* Note: these code should be removed finally, don't need
485 int prepare_unaligned_write(struct llu_sysio_cookie *cookie)
487 struct inode *inode = cookie->lsc_inode;
488 struct llu_inode_info *lli = llu_i2info(inode);
489 struct lov_stripe_md *lsm = lli->lli_smd;
491 struct page *pages = cookie->lsc_pages;
492 int i, pgidx[2] = {0, cookie->lsc_npages-1};
496 for (i = 0; i < 2; i++) {
497 struct page *oldpage = &pages[pgidx[i]];
502 if (i == 0 && pgidx[0] == pgidx[1])
505 LASSERT(oldpage->_offset + oldpage->_count <= PAGE_CACHE_SIZE);
507 if (oldpage->_count == PAGE_CACHE_SIZE)
510 if (oldpage->index << PAGE_CACHE_SHIFT >=
514 newbuf = malloc(PAGE_CACHE_SIZE);
518 newpage.index = oldpage->index;
519 newpage.addr = newbuf;
522 pg.off = ((obd_off)newpage.index << PAGE_CACHE_SHIFT);
523 if (pg.off + PAGE_CACHE_SIZE > lli->lli_st_size)
524 pg.count = lli->lli_st_size % PAGE_CACHE_SIZE;
526 pg.count = PAGE_CACHE_SIZE;
529 oa.o_id = lsm->lsm_object_id;
530 oa.o_mode = lli->lli_st_mode;
531 oa.o_valid = OBD_MD_FLID | OBD_MD_FLMODE | OBD_MD_FLTYPE;
534 rc = obd_brw(OBD_BRW_READ, llu_i2obdexp(inode), &oa, lsm, 1, &pg, NULL);
540 /* copy page content, and reset page params */
541 memcpy(newbuf + oldpage->_offset,
542 (char*)oldpage->addr + oldpage->_offset,
545 oldpage->addr = newbuf;
546 if ((((obd_off)oldpage->index << PAGE_CACHE_SHIFT) +
547 oldpage->_offset + oldpage->_count) > lli->lli_st_size)
548 oldpage->_count += oldpage->_offset;
550 oldpage->_count = PAGE_CACHE_SIZE;
551 oldpage->_offset = 0;
552 oldpage->_managed = 1;
560 int llu_prep_async_io(struct llu_sysio_cookie *cookie, int cmd,
561 char *buf, loff_t pos, size_t count)
563 struct llu_inode_info *lli = llu_i2info(cookie->lsc_inode);
564 struct lov_stripe_md *lsm = lli->lli_smd;
565 struct obd_export *exp = llu_i2obdexp(cookie->lsc_inode);
566 struct page *pages = cookie->lsc_pages;
567 struct ll_async_page *llap = cookie->lsc_llap;
568 int i, rc, npages = 0;
574 /* prepare the pages array */
576 unsigned long index, offset, bytes;
578 offset = (pos & ~PAGE_CACHE_MASK);
579 index = pos >> PAGE_CACHE_SHIFT;
580 bytes = PAGE_CACHE_SIZE - offset;
584 /* prevent read beyond file range */
585 if ((cmd == OBD_BRW_READ) &&
586 (pos + bytes) >= lli->lli_st_size) {
587 if (pos >= lli->lli_st_size)
589 bytes = lli->lli_st_size - pos;
592 /* prepare page for this index */
593 pages[npages].index = index;
594 pages[npages].addr = buf - offset;
596 pages[npages]._offset = offset;
597 pages[npages]._count = bytes;
604 cookie->lsc_rwcount += bytes;
607 cookie->lsc_npages = npages;
609 #ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
610 if (cmd == OBD_BRW_WRITE) {
611 rc = prepare_unaligned_write(cookie);
617 for (i = 0; i < npages; i++) {
618 llap[i].llap_magic = LLAP_MAGIC;
619 rc = obd_prep_async_page(exp, lsm, NULL, &pages[i],
620 (obd_off)pages[i].index << PAGE_SHIFT,
622 &llap[i], &llap[i].llap_cookie);
624 llap[i].llap_cookie = NULL;
627 CDEBUG(D_CACHE, "llap %p page %p cookie %p obj off "LPU64"\n",
628 &llap[i], &pages[i], llap[i].llap_cookie,
629 (obd_off)pages[i].index << PAGE_SHIFT);
630 pages[i].private = (unsigned long)&llap[i];
631 llap[i].llap_page = &pages[i];
632 llap[i].llap_inode = cookie->lsc_inode;
634 rc = obd_queue_group_io(exp, lsm, NULL, cookie->lsc_oig,
635 llap[i].llap_cookie, cmd,
636 pages[i]._offset, pages[i]._count, 0,
637 ASYNC_READY | ASYNC_URGENT |
638 ASYNC_COUNT_STABLE | ASYNC_GROUP_SYNC);
642 llap[i].llap_queued = 1;
649 int llu_start_async_io(struct llu_sysio_cookie *cookie)
651 struct lov_stripe_md *lsm = llu_i2info(cookie->lsc_inode)->lli_smd;
652 struct obd_export *exp = llu_i2obdexp(cookie->lsc_inode);
654 return obd_trigger_group_io(exp, lsm, NULL, cookie->lsc_oig);
658 * read/write a continuous buffer for an inode (zero-copy)
660 struct llu_sysio_cookie*
661 llu_rw(int cmd, struct inode *inode, char *buf, size_t count, loff_t pos)
663 struct llu_sysio_cookie *cookie;
667 max_pages = (count >> PAGE_SHIFT) + 2;
669 cookie = get_sysio_cookie(inode, max_pages);
671 RETURN(ERR_PTR(-ENOMEM));
673 rc = llu_prep_async_io(cookie, cmd, buf, pos, count);
675 GOTO(out_cleanup, rc);
677 rc = llu_start_async_io(cookie);
679 GOTO(out_cleanup, rc);
684 CERROR("file i/o error!\n");
691 put_sysio_cookie(cookie);
695 void lov_increase_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
698 struct llu_sysio_callback_args*
699 llu_file_write(struct inode *inode, const struct iovec *iovec,
700 size_t iovlen, loff_t pos)
702 struct llu_inode_info *lli = llu_i2info(inode);
703 struct ll_file_data *fd = lli->lli_file_data;
704 struct lustre_handle lockh = {0};
705 struct lov_stripe_md *lsm = lli->lli_smd;
706 struct obd_export *exp = NULL;
707 ldlm_policy_data_t policy;
708 struct llu_sysio_callback_args *lsca;
709 struct llu_sysio_cookie *cookie;
714 /* XXX consider other types later */
715 if (!S_ISREG(lli->lli_st_mode))
718 LASSERT(iovlen <= MAX_IOVEC);
720 exp = llu_i2obdexp(inode);
722 RETURN(ERR_PTR(-EINVAL));
724 OBD_ALLOC(lsca, sizeof(*lsca));
726 RETURN(ERR_PTR(-ENOMEM));
728 /* FIXME optimize the following extent locking */
729 for (iovidx = 0; iovidx < iovlen; iovidx++) {
730 char *buf = (char*)iovec[iovidx].iov_base;
731 size_t count = iovec[iovidx].iov_len;
736 if (pos + count > lli->lli_maxbytes)
737 GOTO(err_out, err = -ERANGE);
739 /* FIXME libsysio haven't handle O_APPEND?? */
740 policy.l_extent.start = pos;
741 policy.l_extent.end = pos + count - 1;
743 err = llu_extent_lock(fd, inode, lsm, LCK_PW, &policy,
746 GOTO(err_out, err = -ENOLCK);
748 CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
749 lli->lli_st_ino, count, pos);
751 cookie = llu_rw(OBD_BRW_WRITE, inode, buf, count, pos);
752 if (!IS_ERR(cookie)) {
754 lsca->cookies[lsca->ncookies++] = cookie;
756 lov_increase_kms(exp, lsm, pos);
758 if (pos > lli->lli_st_size)
759 lli->lli_st_size = pos;
761 llu_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
762 GOTO(err_out, err = PTR_ERR(cookie));
766 err = llu_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
768 CERROR("extent unlock error %d\n", err);
774 /* teardown all async stuff */
775 while (lsca->ncookies--) {
776 put_sysio_cookie(lsca->cookies[lsca->ncookies]);
778 OBD_FREE(lsca, sizeof(*lsca));
780 RETURN(ERR_PTR(err));
784 static void llu_update_atime(struct inode *inode)
786 struct llu_inode_info *lli = llu_i2info(inode);
791 attr.ia_atime = LTIME_S(CURRENT_TIME);
792 attr.ia_valid = ATTR_ATIME;
794 if (lli->lli_st_atime == attr.ia_atime) return;
795 if (IS_RDONLY(inode)) return;
796 if (IS_NOATIME(inode)) return;
798 /* ll_inode_setattr() sets inode->i_atime from attr.ia_atime */
799 llu_inode_setattr(inode, &attr, 0);
801 /* update atime, but don't explicitly write it out just this change */
802 inode->i_atime = CURRENT_TIME;
807 struct llu_sysio_callback_args*
808 llu_file_read(struct inode *inode, const struct iovec *iovec,
809 size_t iovlen, loff_t pos)
811 struct llu_inode_info *lli = llu_i2info(inode);
812 struct ll_file_data *fd = lli->lli_file_data;
813 struct lov_stripe_md *lsm = lli->lli_smd;
814 struct lustre_handle lockh = { 0 };
815 ldlm_policy_data_t policy;
816 struct llu_sysio_callback_args *lsca;
817 struct llu_sysio_cookie *cookie;
824 OBD_ALLOC(lsca, sizeof(*lsca));
826 RETURN(ERR_PTR(-ENOMEM));
828 for (iovidx = 0; iovidx < iovlen; iovidx++) {
829 char *buf = iovec[iovidx].iov_base;
830 size_t count = iovec[iovidx].iov_len;
832 /* "If nbyte is 0, read() will return 0 and have no other results."
833 * -- Single Unix Spec */
837 policy.l_extent.start = pos;
838 policy.l_extent.end = pos + count - 1;
840 err = llu_extent_lock(fd, inode, lsm, LCK_PR, &policy, &lockh, 0);
842 GOTO(err_out, err = -ENOLCK);
844 kms = lov_merge_size(lsm, 1);
845 if (policy.l_extent.end > kms) {
846 /* A glimpse is necessary to determine whether we
847 * return a short read or some zeroes at the end of
850 if (llu_glimpse_size(inode, &lvb)) {
851 llu_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
852 GOTO(err_out, err = -ENOLCK);
854 lli->lli_st_size = lvb.lvb_size;
856 lli->lli_st_size = kms;
859 CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld, "
860 "i_size "LPU64"\n", lli->lli_st_ino, count, pos,
863 if (pos >= lli->lli_st_size) {
864 llu_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
868 cookie = llu_rw(OBD_BRW_READ, inode, buf, count, pos);
869 if (!IS_ERR(cookie)) {
871 lsca->cookies[lsca->ncookies++] = cookie;
874 llu_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
875 GOTO(err_out, err = PTR_ERR(cookie));
879 err = llu_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
881 CERROR("extent_unlock fail: %d\n", err);
885 llu_update_atime(inode);
890 /* teardown all async stuff */
891 while (lsca->ncookies--) {
892 put_sysio_cookie(lsca->cookies[lsca->ncookies]);
894 OBD_FREE(lsca, sizeof(*lsca));
896 RETURN(ERR_PTR(err));
899 int llu_iop_iodone(struct ioctx *ioctxp)
901 struct llu_sysio_callback_args *lsca = ioctxp->ioctx_private;
902 struct llu_sysio_cookie *cookie;
903 int i, err = 0, rc = 0;
906 /* write/read(fd, buf, 0) */
908 ioctxp->ioctx_cc = 0;
912 LASSERT(!IS_ERR(lsca));
914 for (i = 0; i < lsca->ncookies; i++) {
915 cookie = lsca->cookies[i];
917 err = oig_wait(cookie->lsc_oig);
921 ioctxp->ioctx_cc += cookie->lsc_rwcount;
922 put_sysio_cookie(cookie);
928 ioctxp->ioctx_cc = -1;
929 ioctxp->ioctx_errno = -rc;
932 OBD_FREE(lsca, sizeof(*lsca));
933 ioctxp->ioctx_private = NULL;