X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fliblustre%2Fdir.c;h=f685beba1b5fa2ff4e177d0161102ddaacf3e5b2;hp=c236d730e35a56b83bfbf83dc97f799ca6269b43;hb=fbb7ead129258897f5a5d5c9ce28d31fbbe5bca2;hpb=a1d11a561dea2ae38275eedc64d09e1fe1730d6b diff --git a/lustre/liblustre/dir.c b/lustre/liblustre/dir.c index c236d73..f685beb 100644 --- a/lustre/liblustre/dir.c +++ b/lustre/liblustre/dir.c @@ -1,9 +1,9 @@ /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * - * Lustre Light Super operations + * Lustre Light directory handling * - * Copyright (c) 2002, 2003 Cluster File Systems, Inc. + * Copyright (c) 2002-2004 Cluster File Systems, Inc. * * This file is part of Lustre, http://www.lustre.org. * @@ -33,17 +33,32 @@ #include #include +#ifdef HAVE_XTIO_H +#include +#endif #include #include #include #include +#ifdef HAVE_FILE_H #include +#endif #undef LIST_HEAD +#ifdef HAVE_LINUX_TYPES_H #include -#include +#elif defined(HAVE_SYS_TYPES_H) +#include +#endif + +#ifdef HAVE_LINUX_UNISTD_H #include +#elif defined(HAVE_UNISTD_H) +#include +#endif + +#include #include "llite_lib.h" @@ -51,7 +66,7 @@ static int llu_dir_do_readpage(struct inode *inode, struct page *page) { struct llu_inode_info *lli = llu_i2info(inode); struct llu_sb_info *sbi = llu_i2sbi(inode); - struct ll_fid mdc_fid; + struct lustre_id id; __u64 offset; int rc = 0; struct ptlrpc_request *request; @@ -59,31 +74,22 @@ static int llu_dir_do_readpage(struct inode *inode, struct page *page) struct mds_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 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 = {id_fid(&lli->lli_id), id_group(&lli->lli_id)} }; + ldlm_policy_data_t policy = { .l_inodebits = { MDS_INODELOCK_UPDATE } }; ENTRY; - if ((lli->lli_st_size + PAGE_CACHE_SIZE - 1) >> PAGE_SHIFT <= page->index) { - /* XXX why do we need this exactly, and why do we think that - * an all-zero directory page is useful? - */ - CERROR("memsetting dir page %lu to zero (size %lld)\n", - page->index, lli->lli_st_size); - memset(page->addr, 0, PAGE_CACHE_SIZE); - GOTO(readpage_out, rc); - } - rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED, - &res_id, LDLM_PLAIN, NULL, LCK_PR, &lockh); + &res_id, LDLM_IBITS, &policy, LCK_PR, &lockh); if (!rc) { - llu_prepare_mdc_op_data(&data, inode, NULL, NULL, 0, 0); + llu_prepare_mdc_data(&data, inode, NULL, NULL, 0, 0); - rc = mdc_enqueue(sbi->ll_mdc_exp, LDLM_PLAIN, &it, LCK_PR, + rc = mdc_enqueue(sbi->ll_md_exp, LDLM_IBITS, &it, LCK_PR, &data, &lockh, NULL, 0, ldlm_completion_ast, llu_mdc_blocking_ast, inode); - request = (struct ptlrpc_request *)it.d.lustre.it_data; + request = (struct ptlrpc_request *)LUSTRE_IT(&it)->it_data; if (request) ptlrpc_req_finished(request); if (rc < 0) { @@ -93,22 +99,24 @@ 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); + /* FIXME-UMKA: should be here some mds num and mds id? */ + mdc_pack_id(&id, lli->lli_st_ino, lli->lli_st_generation, + S_IFDIR, 0, 0); offset = page->index << PAGE_SHIFT; - rc = mdc_readpage(sbi->ll_mdc_exp, &mdc_fid, - offset, page, &request); + rc = mdc_readpage(sbi->ll_md_exp, &id, 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; + } else { + CERROR("read_dir_page(%ld) error %d\n", page->index, rc); } ptlrpc_req_finished(request); EXIT; - readpage_out: ldlm_lock_decref(&lockh, LCK_PR); return rc; } @@ -135,6 +143,29 @@ static struct page *llu_dir_read_page(struct inode *ino, int pgidx) return page; } +enum { + EXT2_FT_UNKNOWN, + EXT2_FT_REG_FILE, + EXT2_FT_DIR, + EXT2_FT_CHRDEV, + EXT2_FT_BLKDEV, + EXT2_FT_FIFO, + EXT2_FT_SOCK, + EXT2_FT_SYMLINK, + EXT2_FT_MAX +}; + +static unsigned char ext2_filetype_table[EXT2_FT_MAX] = { + [EXT2_FT_UNKNOWN] DT_UNKNOWN, + [EXT2_FT_REG_FILE] DT_REG, + [EXT2_FT_DIR] DT_DIR, + [EXT2_FT_CHRDEV] DT_CHR, + [EXT2_FT_BLKDEV] DT_BLK, + [EXT2_FT_FIFO] DT_FIFO, + [EXT2_FT_SOCK] DT_SOCK, + [EXT2_FT_SYMLINK] DT_LNK, +}; + #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de))) #define ROUND_UP64(x) (((x)+sizeof(__u64)-1) & ~(sizeof(__u64)-1)) @@ -169,12 +200,19 @@ ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes, int maxpages, pgidx, filled = 0; ENTRY; + if (lli->lli_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_CACHE_SHIFT; - pgidx = pos >> PAGE_CACHE_SHIFT; - offset = pos & ~PAGE_CACHE_MASK; + maxpages = (lli->lli_st_size + PAGE_SIZE - 1) >> PAGE_SHIFT; + pgidx = pos >> PAGE_SHIFT; + offset = pos & ~PAGE_MASK; for ( ; pgidx < maxpages ; pgidx++, offset = 0) { struct page *page; @@ -186,23 +224,24 @@ 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_CACHE_SHIFT; + maxpages = (lli->lli_st_size + PAGE_SIZE - 1) >> PAGE_SHIFT; /* fill in buffer */ addr = page->addr; - limit = addr + PAGE_CACHE_SIZE - EXT2_DIR_REC_LEN(1); + limit = addr + PAGE_SIZE - EXT2_DIR_REC_LEN(1); de = (struct ext2_dirent *) (addr + offset); for ( ; (char*) de <= limit; de = ext2_next_entry(de)) { if (de->inode) { int over; - unsigned char d_type = 0; + unsigned char d_type = DT_UNKNOWN; - /* XXX handle type, etc here */ + if (de->file_type < EXT2_FT_MAX) + d_type = ext2_filetype_table[de->file_type]; offset = (char*) de - addr; over = filldir(buf, nbytes, de->name, de->name_len, - (pgidx << PAGE_CACHE_SHIFT) | offset, + (pgidx << PAGE_SHIFT) | offset, le32_to_cpu(de->inode), d_type, &filled); if (over) { free_page(page); @@ -214,7 +253,7 @@ ssize_t llu_iop_getdirentries(struct inode *ino, char *buf, size_t nbytes, free_page(page); } done: - lli->lli_dir_pos = pgidx << PAGE_CACHE_SHIFT | offset; + lli->lli_dir_pos = pgidx << PAGE_SHIFT | offset; *basep = lli->lli_dir_pos; RETURN(filled); }