From cda486e020bef3f679c0e87b619cab0938b189f3 Mon Sep 17 00:00:00 2001 From: braam Date: Sun, 23 Jun 2002 00:47:37 +0000 Subject: [PATCH] - fixes for truncating new files with intent locks - fixes for truncating the data objects ** Andreas: check branch too please! - fixes for mode setting in open_namei path - remove useless setattr from mds - change test truncates to bytes, not kilo bytes - improve the intent-test.sh --- lustre/llite/rw.c | 11 ++++++++--- lustre/mdc/mdc_request.c | 1 + lustre/mds/handler.c | 8 ++++---- lustre/obdfilter/filter.c | 1 + lustre/tests/intent-test.sh | 18 ++++++++++-------- lustre/tests/truncate.c | 3 +-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 39c1d04..8993695 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -192,11 +192,16 @@ void ll_truncate(struct inode *inode) ENTRY; oa = ll_i2info(inode)->lli_obdo; - + if (!oa) { + /* object not yet allocated */ + inode->i_mtime = inode->i_ctime = CURRENT_TIME; + return; + } CDEBUG(D_INFO, "calling punch for %ld (%Lu bytes at 0)\n", (long)oa->o_id, (unsigned long long)oa->o_size); - err = obd_punch(ll_i2obdconn(inode), oa, oa->o_size, 0); - + oa->o_size = inode->i_size; + oa->o_valid = OBD_MD_FLSIZE; + err = obd_punch(ll_i2obdconn(inode), oa, 0, oa->o_size); if (err) CERROR("obd_truncate fails (%d)\n", err); else diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 7d2b570..af47ad8 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -187,6 +187,7 @@ int mdc_enqueue(struct obd_conn *conn, int lock_type, struct lookup_intent *it, break; case (IT_CREAT|IT_OPEN): case IT_CREAT: + case IT_MKNOD: it->it_mode = (it->it_mode | S_IFREG) & ~current->fs->umask; break; case IT_SYMLINK: diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index a94aa77..a28954d 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -510,13 +510,13 @@ static int mds_open(struct ptlrpc_request *req) if (req->rq_reqmsg->bufcount > 1) { void *handle; struct inode *inode = de->d_inode; - struct iattr iattr; + //struct iattr iattr; struct obdo *obdo; int rc; obdo = lustre_msg_buf(req->rq_reqmsg, 1); - iattr.ia_valid = ATTR_MODE; - iattr.ia_mode = inode->i_mode; + //iattr.ia_valid = ATTR_MODE; + //iattr.ia_mode = inode->i_mode; handle = mds_fs_start(mds, de->d_inode, MDS_FSOP_SETATTR); if (!handle) { @@ -526,7 +526,7 @@ static int mds_open(struct ptlrpc_request *req) /* XXX error handling */ rc = mds_fs_set_obdo(mds, inode, handle, obdo); - rc = mds_fs_setattr(mds, de, handle, &iattr); + // rc = mds_fs_setattr(mds, de, handle, &iattr); if (!rc) rc = mds_update_last_rcvd(mds, handle, req); else { diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 8148df7..2bb1be8 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -713,6 +713,7 @@ static int filter_truncate(struct obd_conn *conn, struct obdo *oa, CDEBUG(D_INODE, "calling truncate for object #%Ld, valid = %x, " "o_size = %Ld\n", oa->o_id, oa->o_valid, oa->o_size); + oa->o_valid = OBD_MD_FLSIZE; error = filter_setattr(conn, oa); oa->o_valid = OBD_MD_FLBLOCKS | OBD_MD_FLCTIME | OBD_MD_FLMTIME; diff --git a/lustre/tests/intent-test.sh b/lustre/tests/intent-test.sh index f18da49..ed66a30 100755 --- a/lustre/tests/intent-test.sh +++ b/lustre/tests/intent-test.sh @@ -1,7 +1,7 @@ #!/bin/bash -x -OST=2 -MDS=3 +OST=`../utils/obdctl name2dev OSCDEV` +MDS=`../utils/obdctl name2dev MDCDEV` mkdir /mnt/lustre/foo mkdir /mnt/lustre/foo2 @@ -75,9 +75,6 @@ touch /mnt/lustre/bar5 umount /mnt/lustre mount -t lustre_lite -o ost=$OST,mds=$MDS none /mnt/lustre -echo "ready debugger" -read - echo foo >> /mnt/lustre/bar cat /mnt/lustre/bar @@ -86,8 +83,6 @@ mount -t lustre_lite -o ost=$OST,mds=$MDS none /mnt/lustre cat /mnt/lustre/bar -exit; - echo foo >> /mnt/lustre/iotest echo bar >> /mnt/lustre/iotest cat /mnt/lustre/iotest @@ -119,4 +114,11 @@ ls /mnt/lustre umount /mnt/lustre mount -t lustre_lite -o ost=$OST,mds=$MDS none /mnt/lustre -cat /mnt/lustre/iotest \ No newline at end of file +echo "Testing truncation..." +echo foo > /mnt/lustre/iotest +echo bar >> /mnt/lustre/iotest +cat /mnt/lustre/iotest +echo "trucating to 3 bytes now..." +./truncate /mnt/lustre/iotest 4 +cat /mnt/lustre/iotest + diff --git a/lustre/tests/truncate.c b/lustre/tests/truncate.c index 70fbbc7..3c3ad94 100644 --- a/lustre/tests/truncate.c +++ b/lustre/tests/truncate.c @@ -10,12 +10,11 @@ int main(int argc, char **argv) int err; if (argc != 3) { - printf("usage %s file offset (kilobytes)\n", argv[0]); + printf("usage %s file bytes\n", argv[0]); return 1; } off = strtoul(argv[2], NULL, 0); - off *= 1024; err = truncate64(argv[1], off); if ( err ) { printf("Error truncating %s: %s\n", argv[1], strerror(errno)); -- 1.8.3.1