Whamcloud - gitweb
- sequence width on clients, super-width and meta-width on servers are dynamic now...
[fs/lustre-release.git] / lustre / liblustre / dir.c
index 3b9b0f6..e48a29a 100644 (file)
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 #include <sys/queue.h>
 
+#ifdef HAVE_XTIO_H
+#include <xtio.h>
+#endif
 #include <sysio.h>
 #include <fs.h>
 #include <mount.h>
 #include <inode.h>
+#ifdef HAVE_FILE_H
 #include <file.h>
+#endif
 
 #undef LIST_HEAD
 
-#include <linux/types.h>
+#ifdef HAVE_ASM_TYPES_H
+#include <asm/types.h>
+#elif defined(HAVE_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_LINUX_UNISTD_H
 #include <linux/unistd.h>
+#elif defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+
 #include <dirent.h>
 
 #include "llite_lib.h"
 static int llu_dir_do_readpage(struct inode *inode, struct page *page)
 {
         struct llu_inode_info *lli = llu_i2info(inode);
+        struct intnl_stat *st = llu_i2stat(inode);
         struct llu_sb_info *sbi = llu_i2sbi(inode);
-        struct ll_fid mdc_fid;
         __u64 offset;
         int rc = 0;
         struct ptlrpc_request *request;
         struct lustre_handle lockh;
-        struct mds_body *body;
+        struct mdt_body *body;
         struct lookup_intent it = { .it_op = IT_READDIR };
-        struct mdc_op_data data;
-        struct obd_device *obddev = class_exp2obd(sbi->ll_mdc_exp);
+        struct md_op_data op_data = { { 0 } };
+        struct obd_device *obddev = class_exp2obd(sbi->ll_md_exp);
         struct ldlm_res_id res_id =
-                { .name = {lli->lli_st_ino, (__u64)lli->lli_st_generation} };
+                { .name = {fid_seq(&lli->lli_fid), 
+                           fid_oid(&lli->lli_fid), 
+                           fid_ver(&lli->lli_fid)} };
         ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_UPDATE } };
         ENTRY;
 
         rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
-                             &res_id, LDLM_IBITS, &policy, LCK_PR, &lockh);
+                             &res_id, LDLM_IBITS, &policy, LCK_CR, &lockh);
         if (!rc) {
-                llu_prepare_mdc_op_data(&data, inode, NULL, NULL, 0, 0);
+                llu_prepare_md_op_data(&op_data, inode, NULL, NULL, 0, 0);
 
-                rc = mdc_enqueue(sbi->ll_mdc_exp, LDLM_IBITS, &it, LCK_PR,
-                                 &data, &lockh, NULL, 0,
-                                 ldlm_completion_ast, llu_mdc_blocking_ast,
-                                 inode);
+                rc = md_enqueue(sbi->ll_md_exp, LDLM_IBITS, &it, LCK_CR,
+                                &op_data, &lockh, NULL, 0,
+                                ldlm_completion_ast, llu_mdc_blocking_ast,
+                                inode, LDLM_FL_CANCEL_ON_BLOCK);
                 request = (struct ptlrpc_request *)it.d.lustre.it_data;
                 if (request)
                         ptlrpc_req_finished(request);
@@ -84,24 +101,22 @@ static int llu_dir_do_readpage(struct inode *inode, struct page *page)
         }
         ldlm_lock_dump_handle(D_OTHER, &lockh);
 
-        mdc_pack_fid(&mdc_fid, lli->lli_st_ino, lli->lli_st_generation, S_IFDIR);
-
         offset = page->index << PAGE_SHIFT;
-        rc = mdc_readpage(sbi->ll_mdc_exp, &mdc_fid,
-                          offset, page, &request);
+        rc = md_readpage(sbi->ll_md_exp, &lli->lli_fid,
+                         offset, page, &request);
         if (!rc) {
                 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body));
                 LASSERT (body != NULL);         /* checked by mdc_readpage() */
                 LASSERT_REPSWABBED (request, 0); /* swabbed by mdc_readpage() */
 
-                lli->lli_st_size = body->size;
+                st->st_size = body->size;
         } else {
                 CERROR("read_dir_page(%ld) error %d\n", page->index, rc);
         }
         ptlrpc_req_finished(request);
         EXIT;
 
-        ldlm_lock_decref(&lockh, LCK_PR);
+        ldlm_lock_decref(&lockh, LCK_CR);
         return rc;
 }
 
@@ -165,9 +180,11 @@ static int filldir(char *buf, int buflen,
                 return 1;
 
         dirent->d_ino = ino;
-        dirent->d_off = offset,
+        dirent->d_off = offset;
         dirent->d_reclen = reclen;
+#ifndef _AIX
         dirent->d_type = (unsigned short) d_type;
+#endif
         memcpy(dirent->d_name, name, namelen);
         dirent->d_name[namelen] = 0;
 
@@ -176,25 +193,26 @@ static int filldir(char *buf, int buflen,
         return 0;
 }
 
-ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
-                              _SYSIO_OFF_T *basep)
+ssize_t llu_iop_filldirentries(struct inode *ino, _SYSIO_OFF_T *basep, 
+                              char *buf, size_t nbytes)
 {
         struct llu_inode_info *lli = llu_i2info(ino);
+        struct intnl_stat *st = llu_i2stat(ino);
         loff_t pos = *basep, offset;
         int maxpages, pgidx, filled = 0;
         ENTRY;
 
-        if (lli->lli_st_size == 0) {
+        liblustre_wait_event(0);
+
+        if (st->st_size == 0) {
                 CWARN("dir size is 0?\n");
                 RETURN(0);
         }
 
-        liblustre_wait_event(0);
-
         if (pos == -1)
                 pos = lli->lli_dir_pos;
 
-        maxpages = (lli->lli_st_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+        maxpages = (st->st_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
         pgidx = pos >> PAGE_SHIFT;
         offset = pos & ~PAGE_MASK;
 
@@ -208,7 +226,7 @@ ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
                         continue;
 
                 /* size might have been updated by mdc_readpage */
-                maxpages = (lli->lli_st_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
+                maxpages = (st->st_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
                 /* fill in buffer */
                 addr = page->addr;
@@ -225,7 +243,7 @@ ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
 
                                 offset = (char*) de - addr;
                                 over =  filldir(buf, nbytes, de->name, de->name_len,
-                                                (pgidx << PAGE_SHIFT) | offset,
+                                                ((pgidx << PAGE_SHIFT) | offset) + le16_to_cpu(de->rec_len),
                                                 le32_to_cpu(de->inode), d_type, &filled);
                                 if (over) {
                                         free_page(page);
@@ -239,5 +257,6 @@ ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes,
 done:
         lli->lli_dir_pos = pgidx << PAGE_SHIFT | offset;
         *basep = lli->lli_dir_pos;
+        liblustre_wait_event(0);
         RETURN(filled);
 }