From 762b1ae4bbc9b3e861007142a62df1cabad6980d Mon Sep 17 00:00:00 2001 From: adilger Date: Fri, 5 Jul 2002 07:41:44 +0000 Subject: [PATCH] Add statfs support for proper blocks count to head. Includes fix for type == 0 (truncate) problem. Removes ost_get_info call - it is not used and causes confusion. --- lustre/llite/rw.c | 26 +++++++++-------------- lustre/llite/super.c | 52 ++++++++++++++++++++++++++++++++-------------- lustre/mds/handler.c | 4 ---- lustre/obdfilter/filter.c | 42 +++++++++++++++---------------------- lustre/osc/Makefile.am | 5 ++++- lustre/osc/osc_request.c | 53 ++++++++++++++++++++++++----------------------- lustre/ost/Makefile.am | 5 ++++- lustre/ost/ost_handler.c | 51 ++++++++++++++++++++++----------------------- 8 files changed, 123 insertions(+), 115 deletions(-) diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 2154c72..06625a1 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -219,14 +219,14 @@ void ll_truncate(struct inode *inode) int ll_direct_IO(int rw, struct inode *inode, struct kiobuf *iobuf, unsigned long blocknr, int blocksize) { - int i; obd_count num_obdo = 1; obd_count bufs_per_obdo = iobuf->nr_pages; - struct obdo *oa = NULL; + struct obdo *oa = NULL; obd_size *count = NULL; obd_off *offset = NULL; obd_flag *flags = NULL; int rc = 0; + int i; ENTRY; @@ -286,17 +286,11 @@ int ll_flush_inode_pages(struct inode * inode) spin_unlock(&pagecache_lock); - OBD_ALLOC(count, sizeof(obd_size) * bufs_per_obdo); - if (!count) - GOTO(out, err=-ENOMEM); - - OBD_ALLOC(offset, sizeof(obd_off) * bufs_per_obdo); - if (!offset) - GOTO(out, err=-ENOMEM); - - OBD_ALLOC(flags, sizeof(obd_flag) * bufs_per_obdo); - if (!flags) - GOTO(out, err=-ENOMEM); + OBD_ALLOC(count, sizeof(*count) * bufs_per_obdo); + OBD_ALLOC(offset, sizeof(*offset) * bufs_per_obdo); + OBD_ALLOC(flags, sizeof(*flags) * bufs_per_obdo); + if (!count || !offset || !flags) + GOTO(out, err=-ENOMEM); #if 0 for (i = 0 ; i < bufs_per_obdo ; i++) { @@ -316,9 +310,9 @@ int ll_flush_inode_pages(struct inode * inode) #endif out: obdo_free(oa); - OBD_FREE(flags, sizeof(obd_flag) * bufs_per_obdo); - OBD_FREE(count, sizeof(obd_count) * bufs_per_obdo); - OBD_FREE(offset, sizeof(obd_off) * bufs_per_obdo); + OBD_FREE(flags, sizeof(*flags) * bufs_per_obdo); + OBD_FREE(count, sizeof(*count) * bufs_per_obdo); + OBD_FREE(offset, sizeof(*offset) * bufs_per_obdo); RETURN(err); } diff --git a/lustre/llite/super.c b/lustre/llite/super.c index fd2aa8b..f1d007e 100644 --- a/lustre/llite/super.c +++ b/lustre/llite/super.c @@ -75,6 +75,10 @@ static void ll_options(char *options, char **ost, char **mds) EXIT; } +#ifndef log2 +#define log2(n) ffz(~(n)) +#endif + static struct super_block * ll_read_super(struct super_block *sb, void *data, int silent) { @@ -85,6 +89,7 @@ static struct super_block * ll_read_super(struct super_block *sb, int devno; int err; struct ll_fid rootfid; + struct statfs sfs; __u64 last_committed, last_rcvd; __u32 last_xid; struct ptlrpc_request *request = NULL; @@ -157,15 +162,16 @@ static struct super_block * ll_read_super(struct super_block *sb, CERROR("cannot mds_connect: rc = %d\n", err); GOTO(out_disc, sb = NULL); } - CDEBUG(D_SUPER, "rootfid %ld\n", (unsigned long)rootfid.id); + CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id); sbi->ll_rootino = rootfid.id; - sb->s_maxbytes = 1ULL << 36; - /* XXX get this with a get_info call (like we have in OBDFS), - this info call should return the blocksize of the MDS (statfs?) */ - sb->s_blocksize = 4096; - sb->s_blocksize_bits = 12; + memset(&sfs, 0, sizeof(sfs)); + err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request); + sb->s_blocksize = sfs.f_bsize; + sb->s_blocksize_bits = log2(sfs.f_bsize); sb->s_magic = LL_SUPER_MAGIC; + sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize; + sb->s_op = &ll_super_operations; /* make root inode */ @@ -341,22 +347,36 @@ int ll_setattr(struct dentry *de, struct iattr *attr) static int ll_statfs(struct super_block *sb, struct statfs *sfs) { struct ptlrpc_request *request = NULL; + struct statfs obd_sfs; struct ll_sb_info *sbi = ll_s2sbi(sb); - int err; + int rc; ENTRY; memset(sfs, 0, sizeof(*sfs)); - err = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request); - if (err) - CERROR("obd_statfs fails (%d)\n", err); - else - CDEBUG(D_SUPER, - "statfs returns blocks %ld/%ld objects %ld/%ld\n", - sfs->f_bavail, sfs->f_blocks, sfs->f_files,sfs->f_ffree); - + rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request); ptlrpc_req_finished(request); + if (rc) { + CERROR("obd_statfs fails: rc = %d\n", rc); + GOTO(out, rc); + } + CDEBUG(D_SUPER, "statfs returns blocks %ld/%ld objects %ld/%ld\n", + sfs->f_bavail, sfs->f_blocks, sfs->f_files,sfs->f_ffree); + + /* temporary until mds_statfs returns statfs info for all OSTs */ + rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs); + if (rc) { + CERROR("obd_statfs fails: rc = %d\n", rc); + GOTO(out, rc); + } + CDEBUG(D_SUPER, "obd_statfs returns blocks %ld/%ld\n", + obd_sfs.f_bavail, obd_sfs.f_blocks); - RETURN(err); + sfs->f_bfree = obd_sfs.f_bfree; + sfs->f_bavail = obd_sfs.f_bavail; + sfs->f_blocks = obd_sfs.f_blocks; + +out: + RETURN(rc); } static void ll_to_inode(struct inode *dst, struct ll_inode_md *md) diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 81a3a31..d625aca 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -488,10 +488,6 @@ static int mds_statfs(struct ptlrpc_request *req) } osfs = lustre_msg_buf(req->rq_repmsg, 0); memset(osfs, 0, size); - /* FIXME: hack until the MDS gets the OST data, next month */ - sfs.f_blocks = -1; - sfs.f_bfree = -1; - sfs.f_bavail = -1; obd_statfs_pack(osfs, &sfs); out: diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 22fa20a..e18d73a 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -537,15 +537,14 @@ static int filter_setattr(struct lustre_handle *conn, struct obdo *oa) int rc; ENTRY; - dentry = filter_fid2dentry(obd, filter_parent(obd, oa->o_mode), - oa->o_id, oa->o_mode); + iattr_from_obdo(&iattr, oa); + iattr.ia_mode = (iattr.ia_mode & ~S_IFMT) | S_IFREG; + dentry = filter_fid2dentry(obd, filter_parent(obd, iattr.ia_mode), + oa->o_id, iattr.ia_mode); if (IS_ERR(dentry)) RETURN(PTR_ERR(dentry)); inode = dentry->d_inode; - iattr_from_obdo(&iattr, oa); - iattr.ia_mode &= ~S_IFMT; - iattr.ia_mode |= S_IFREG; lock_kernel(); if (iattr.ia_mode & ATTR_SIZE) down(&inode->i_sem); @@ -657,8 +656,9 @@ static int filter_create(struct lustre_handle* conn, struct obdo *oa) static int filter_destroy(struct lustre_handle *conn, struct obdo *oa) { - struct obd_run_ctxt saved; struct obd_device *obd; + struct filter_obd *filter; + struct obd_run_ctxt saved; struct obd_export *export; struct inode *inode; struct dentry *dir_dentry, *object_dentry; @@ -670,7 +670,7 @@ static int filter_destroy(struct lustre_handle *conn, struct obdo *oa) RETURN(-EINVAL); } - CDEBUG(D_INODE, "destroying object %Ld\n",oa->o_id); + CDEBUG(D_INODE, "destroying object %Ld\n", oa->o_id); obd = class_conn2obd(conn); dir_dentry = filter_parent(obd, oa->o_mode); @@ -684,11 +684,13 @@ static int filter_destroy(struct lustre_handle *conn, struct obdo *oa) inode = object_dentry->d_inode; if (inode->i_nlink != 1) { CERROR("destroying inode with nlink = %d\n", inode->i_nlink); + LBUG(); inode->i_nlink = 1; } inode->i_mode = S_IFREG; - push_ctxt(&saved, &obd->u.filter.fo_ctxt); + filter = &obd->u.filter; + push_ctxt(&saved, &filter->fo_ctxt); rc = vfs_unlink(dir_dentry->d_inode, object_dentry); pop_ctxt(&saved); @@ -1284,23 +1286,13 @@ out_ctxt: RETURN(0); } -static int filter_statfs(struct lustre_handle *conn, struct statfs * statfs) +static int filter_statfs(struct lustre_handle *conn, struct statfs *statfs) { - struct super_block *sb; - int err; - ENTRY; - - if (!class_conn2export(conn)) { - CDEBUG(D_IOCTL, "invalid client %Lx\n", conn->addr); - RETURN(-EINVAL); - } - - sb = class_conn2obd(conn)->u.filter.fo_sb; - - err = sb->s_op->statfs(sb, statfs); - RETURN(err); -} /* filter_statfs */ + struct obd_device *obd = class_conn2obd(conn); + ENTRY; + RETURN(vfs_statfs(obd->u.filter.fo_sb, statfs)); +} static int filter_get_info(struct lustre_handle *conn, obd_count keylen, void *key, obd_count *vallen, void **val) @@ -1332,8 +1324,8 @@ static int filter_get_info(struct lustre_handle *conn, obd_count keylen, if ( keylen == strlen("root_ino") && memcmp(key, "root_ino", keylen) == 0 ){ - *vallen = sizeof(long); - *val = (void *)(long)FILTER_ROOTINO; + *vallen = sizeof(obd_id); + *val = (void *)(obd_id)FILTER_ROOTINO; RETURN(0); } diff --git a/lustre/osc/Makefile.am b/lustre/osc/Makefile.am index d3e3be8..769b5dd 100644 --- a/lustre/osc/Makefile.am +++ b/lustre/osc/Makefile.am @@ -9,12 +9,15 @@ MODULE = osc modulefs_DATA = osc.o EXTRA_PROGRAMS = osc -LINX= obd_pack.c +LINX= obd_pack.c ll_pack.c osc_SOURCES = obd_pack.c osc_request.c # super.c rw.c file.c dir.c sysctl.c super.c namei.c symlink.c obd_pack.c: test -e obd_pack.c || ln -sf $(top_srcdir)/lib/obd_pack.c +ll_pack.c: + test -e ll_pack.c || ln -sf $(top_srcdir)/lib/ll_pack.c + dist-hook: list='$(LINX)'; for f in $$list; do rm -f $(distdir)/$$f; done diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index fd8e85d..506d712 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -153,7 +153,7 @@ static int osc_getattr(struct lustre_handle *conn, struct obdo *oa) EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } static int osc_open(struct lustre_handle *conn, struct obdo *oa) @@ -228,7 +228,7 @@ static int osc_close(struct lustre_handle *conn, struct obdo *oa) EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } static int osc_setattr(struct lustre_handle *conn, struct obdo *oa) @@ -258,7 +258,7 @@ static int osc_setattr(struct lustre_handle *conn, struct obdo *oa) out: ptlrpc_free_req(request); - return 0; + return rc; } static int osc_create(struct lustre_handle *conn, struct obdo *oa) @@ -307,7 +307,7 @@ static int osc_create(struct lustre_handle *conn, struct obdo *oa) EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } static int osc_punch(struct lustre_handle *conn, struct obdo *oa, obd_size count, @@ -349,7 +349,7 @@ static int osc_punch(struct lustre_handle *conn, struct obdo *oa, obd_size count EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } static int osc_destroy(struct lustre_handle *conn, struct obdo *oa) @@ -389,7 +389,7 @@ static int osc_destroy(struct lustre_handle *conn, struct obdo *oa) EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } struct osc_brw_cb_data { @@ -821,8 +821,7 @@ static int osc_cleanup(struct obd_device * obddev) return 0; } -#if 0 -static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs); +static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs) { struct ptlrpc_request *request; struct ptlrpc_client *cl; @@ -840,34 +839,36 @@ static int osc_statfs(struct lustre_handle *conn, struct statfs *sfs); rc = ptlrpc_queue_wait(request); rc = ptlrpc_check_status(request, rc); - if (rc) + if (rc) { + CERROR("%s failed: rc = %d\n", __FUNCTION__, rc); GOTO(out, rc); + } osfs = lustre_msg_buf(request->rq_repmsg, 0); - obd_statfs_unpack(sfs, osfs); + obd_statfs_unpack(osfs, sfs); EXIT; out: ptlrpc_free_req(request); - return 0; + return rc; } -#endif struct obd_ops osc_obd_ops = { - o_setup: osc_setup, - o_cleanup: osc_cleanup, - o_create: osc_create, - o_destroy: osc_destroy, - o_getattr: osc_getattr, - o_setattr: osc_setattr, - o_open: osc_open, - o_close: osc_close, - o_connect: osc_connect, - o_disconnect: osc_disconnect, - o_brw: osc_brw, - o_punch: osc_punch, - o_enqueue: osc_enqueue, - o_cancel: osc_cancel + o_setup: osc_setup, + o_cleanup: osc_cleanup, + o_statfs: osc_statfs, + o_create: osc_create, + o_destroy: osc_destroy, + o_getattr: osc_getattr, + o_setattr: osc_setattr, + o_open: osc_open, + o_close: osc_close, + o_connect: osc_connect, + o_disconnect: osc_disconnect, + o_brw: osc_brw, + o_punch: osc_punch, + o_enqueue: osc_enqueue, + o_cancel: osc_cancel }; static int __init osc_init(void) diff --git a/lustre/ost/Makefile.am b/lustre/ost/Makefile.am index 132480b..507f667 100644 --- a/lustre/ost/Makefile.am +++ b/lustre/ost/Makefile.am @@ -8,7 +8,10 @@ MODULE = ost modulefs_DATA = ost.o EXTRA_PROGRAMS = ost -LINX=page.c obd_pack.c l_net.c +LINX=page.c obd_pack.c l_net.c ll_pack.c +ll_pack.c: + test -e ll_pack.c || ln -sf $(top_srcdir)/lib/ll_pack.c + obd_pack.c: test -e obd_pack.c || ln -sf $(top_srcdir)/lib/obd_pack.c diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c index 848ddac..4f72272 100644 --- a/lustre/ost/ost_handler.c +++ b/lustre/ost/ost_handler.c @@ -74,6 +74,31 @@ static int ost_getattr(struct ptlrpc_request *req) RETURN(0); } +static int ost_statfs(struct ptlrpc_request *req) +{ + struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg; + struct obd_statfs *osfs; + struct statfs sfs; + int rc, size = sizeof(*osfs); + ENTRY; + + rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg); + if (rc) + RETURN(rc); + + rc = obd_statfs(conn, &sfs); + if (rc) { + CERROR("ost: statfs failed: rc %d\n", rc); + GOTO(out, rc); + } + osfs = lustre_msg_buf(req->rq_repmsg, 0); + memset(osfs, 0, size); + obd_statfs_pack(osfs, &sfs); +out: + req->rq_status = rc; + RETURN(0); +} + static int ost_open(struct ptlrpc_request *req) { struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg; @@ -170,30 +195,6 @@ static int ost_setattr(struct ptlrpc_request *req) RETURN(0); } -static int ost_get_info(struct ptlrpc_request *req) -{ - struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg; - struct ost_body *body; - int rc, size[2] = {sizeof(*body)}; - char *bufs[2] = {NULL, NULL}, *ptr; - ENTRY; - - body = lustre_msg_buf(req->rq_reqmsg, 0); - - ptr = lustre_msg_buf(req->rq_reqmsg, 1); - if (!ptr) - RETURN(-EINVAL); - - req->rq_status = obd_get_info(conn, req->rq_reqmsg->buflens[1], ptr, - &(size[1]), (void **)&(bufs[1])); - - rc = lustre_pack_msg(2, size, bufs, &req->rq_replen, &req->rq_repmsg); - if (rc) - CERROR("cannot pack reply\n"); - - RETURN(rc); -} - static int ost_brw_read(struct ptlrpc_request *req) { struct lustre_handle *conn = (struct lustre_handle *)req->rq_reqmsg; @@ -488,13 +489,11 @@ static int ost_handle(struct ptlrpc_request *req) OBD_FAIL_RETURN(OBD_FAIL_OST_PUNCH_NET, 0); rc = ost_punch(req); break; -#if 0 case OST_STATFS: CDEBUG(D_INODE, "statfs\n"); OBD_FAIL_RETURN(OBD_FAIL_OST_STATFS_NET, 0); rc = ost_statfs(req); break; -#endif default: req->rq_status = -ENOTSUPP; rc = ptlrpc_error(req->rq_svc, req); -- 1.8.3.1