Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / liblustre / rw.c
index 9fe16e5..546ab73 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Lustre Light block IO
+ * Lustre Light Super operations
  *
  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
  *
@@ -75,12 +75,13 @@ static int llu_extent_lock_callback(struct ldlm_lock *lock,
         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);
@@ -94,7 +95,7 @@ static int llu_extent_lock_callback(struct ldlm_lock *lock,
                 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);
@@ -123,7 +124,7 @@ iput:
         default:
                 LBUG();
         }
-
+        
         RETURN(0);
 }
 
@@ -181,7 +182,7 @@ int llu_glimpse_size(struct inode *inode, struct ost_lvb *lvb)
         struct llu_inode_info *lli = llu_i2info(inode);
         struct llu_sb_info *sbi = llu_i2sbi(inode);
         ldlm_policy_data_t policy = { .l_extent = { 0, OBD_OBJECT_EOF } };
-        struct lustre_handle lockh = { 0 };
+        struct lustre_handle lockh;
         int rc, flags = LDLM_FL_HAS_INTENT;
         ENTRY;
 
@@ -387,7 +388,7 @@ static void llu_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
 }
 
 /* called for each page in a completed rpc.*/
-static void llu_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
+static void llu_ap_completion(void *data, int cmd, int rc)
 {
         struct ll_async_page *llap;
         struct page *page;
@@ -448,12 +449,21 @@ void put_sysio_cookie(struct llu_sysio_cookie *cookie)
         struct lov_stripe_md *lsm = llu_i2info(cookie->lsc_inode)->lli_smd;
         struct obd_export *exp = llu_i2obdexp(cookie->lsc_inode);
         struct ll_async_page *llap = cookie->lsc_llap;
+#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+        struct page *pages = cookie->lsc_pages;
+#endif
         int i;
 
         for (i = 0; i< cookie->lsc_maxpages; i++) {
                 if (llap[i].llap_cookie)
                         obd_teardown_async_page(exp, lsm, NULL,
                                                 llap[i].llap_cookie);
+#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+                if (pages[i]._managed) {
+                        free(pages[i].addr);
+                        pages[i]._managed = 0;
+                }
+#endif
         }
 
         I_RELE(cookie->lsc_inode);
@@ -462,6 +472,85 @@ void put_sysio_cookie(struct llu_sysio_cookie *cookie)
         OBD_FREE(cookie, LLU_SYSIO_COOKIE_SIZE(cookie->lsc_maxpages));
 }
 
+#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+/* Note: these code should be removed finally, don't need
+ * more cleanup
+ */
+static
+int prepare_unaligned_write(struct llu_sysio_cookie *cookie)
+{
+        struct inode *inode = cookie->lsc_inode;
+        struct llu_inode_info *lli = llu_i2info(inode);
+        struct lov_stripe_md *lsm = lli->lli_smd;
+        struct obdo oa;
+        struct page *pages = cookie->lsc_pages;
+        int i, pgidx[2] = {0, cookie->lsc_npages-1};
+        int rc;
+        ENTRY;
+
+        for (i = 0; i < 2; i++) {
+                struct page *oldpage = &pages[pgidx[i]];
+                struct page newpage;
+                struct brw_page pg;
+                char *newbuf;
+
+                if (i == 0 && pgidx[0] == pgidx[1])
+                        continue;
+
+                LASSERT(oldpage->_offset + oldpage->_count <= PAGE_CACHE_SIZE);
+
+                if (oldpage->_count == PAGE_CACHE_SIZE)
+                        continue;
+
+                if (oldpage->index << PAGE_CACHE_SHIFT >=
+                    lli->lli_st_size)
+                        continue;
+
+                newbuf = malloc(PAGE_CACHE_SIZE);
+                if (!newbuf)
+                        return -ENOMEM;
+
+                newpage.index = oldpage->index;
+                newpage.addr = newbuf;
+
+                pg.pg = &newpage;
+                pg.off = ((obd_off)newpage.index << PAGE_CACHE_SHIFT);
+                if (pg.off + PAGE_CACHE_SIZE > lli->lli_st_size)
+                        pg.count = lli->lli_st_size % PAGE_CACHE_SIZE;
+                else
+                        pg.count = PAGE_CACHE_SIZE;
+                pg.flag = 0;
+
+                oa.o_id = lsm->lsm_object_id;
+                oa.o_mode = lli->lli_st_mode;
+                oa.o_valid = OBD_MD_FLID | OBD_MD_FLMODE | OBD_MD_FLTYPE;
+
+                /* issue read */
+                rc = obd_brw(OBD_BRW_READ, llu_i2obdexp(inode), &oa, lsm, 1, &pg, NULL);
+                if (rc) {
+                        free(newbuf);
+                        RETURN(rc);
+                }
+
+                /* copy page content, and reset page params */
+                memcpy(newbuf + oldpage->_offset,
+                       (char*)oldpage->addr + oldpage->_offset,
+                       oldpage->_count);
+
+                oldpage->addr = newbuf;
+                if ((((obd_off)oldpage->index << PAGE_CACHE_SHIFT) +
+                    oldpage->_offset + oldpage->_count) > lli->lli_st_size)
+                        oldpage->_count += oldpage->_offset;
+                else
+                        oldpage->_count = PAGE_CACHE_SIZE;
+                oldpage->_offset = 0;
+                oldpage->_managed = 1;
+        }
+
+        RETURN(0);
+}
+#endif
+
 static
 int llu_prep_async_io(struct llu_sysio_cookie *cookie, int cmd,
                       char *buf, loff_t pos, size_t count)
@@ -512,6 +601,14 @@ int llu_prep_async_io(struct llu_sysio_cookie *cookie, int cmd,
 
         cookie->lsc_npages = npages;
 
+#ifdef LIBLUSTRE_HANDLE_UNALIGNED_PAGE
+        if (cmd == OBD_BRW_WRITE) {
+                rc = prepare_unaligned_write(cookie);
+                if (rc)
+                        RETURN(rc);
+        }
+#endif
+
         for (i = 0; i < npages; i++) {
                 llap[i].llap_magic = LLAP_MAGIC;
                 rc = obd_prep_async_page(exp, lsm, NULL, &pages[i],
@@ -645,7 +742,7 @@ llu_file_write(struct inode *inode, const struct iovec *iovec,
                 if (err != ELDLM_OK)
                         GOTO(err_out, err = -ENOLCK);
 
-                CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %llu\n",
+                CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
                        lli->lli_st_ino, count, pos);
 
                 cookie = llu_rw(OBD_BRW_WRITE, inode, buf, count, pos);