Whamcloud - gitweb
- fixed up lustre_mds.h to allow inclusion in userspace testreq.c
authorpschwan <pschwan>
Tue, 2 Apr 2002 00:03:35 +0000 (00:03 +0000)
committerpschwan <pschwan>
Tue, 2 Apr 2002 00:03:35 +0000 (00:03 +0000)
- added ptlrpc_abort_bulk() to help cleanup aborted requests
- changed giant obd_support.h enum into #defines, which will save me hours of
  counting.
- fixed the ioctl interface to the MDC, so testreq works again
- gave testreq a real interface, to just run one test at a time
- ptlrpc_abort() was freeing a variable which would almost always still be NULL.
  Fixed.

14 files changed:
lustre/include/linux/lustre_mds.h
lustre/include/linux/lustre_net.h
lustre/include/linux/obd_support.h
lustre/lib/mds_updates.c
lustre/llite/super.c
lustre/mdc/mdc_reint.c
lustre/mdc/mdc_request.c
lustre/mds/handler.c
lustre/ptlrpc/client.c
lustre/ptlrpc/events.c
lustre/ptlrpc/niobuf.c
lustre/tests/mdcreq.sh
lustre/tests/runfailure-net
lustre/tests/testreq.c

index d3a1a5b..764ef33 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef _LUSTRE_MDS_H
 #define _LUSTRE_MDS_H
 
+#ifdef __KERNEL__
+
 #include <linux/obd_class.h>
 #include <linux/lustre_idl.h>
 #include <linux/lustre_net.h>
@@ -161,6 +163,8 @@ static inline ssize_t mds_fs_readpage(struct mds_obd *mds, struct file *file,
 extern struct mds_fs_operations mds_ext2_fs_ops;
 extern struct mds_fs_operations mds_ext3_fs_ops;
 
+#endif /* __KERNEL__ */
+
 /* ioctls for trying requests */
 #define IOC_REQUEST_TYPE                   'f'
 #define IOC_REQUEST_MIN_NR                 30
@@ -169,6 +173,8 @@ extern struct mds_fs_operations mds_ext3_fs_ops;
 #define IOC_REQUEST_READPAGE            _IOWR('f', 31, long)
 #define IOC_REQUEST_SETATTR             _IOWR('f', 32, long)
 #define IOC_REQUEST_CREATE              _IOWR('f', 33, long)
-#define IOC_REQUEST_MAX_NR               33
+#define IOC_REQUEST_OPEN                _IOWR('f', 34, long)
+#define IOC_REQUEST_CLOSE               _IOWR('f', 35, long)
+#define IOC_REQUEST_MAX_NR               35
 
 #endif
index 011d279..cf2d569 100644 (file)
@@ -201,6 +201,7 @@ int ptlrpc_check_bulk_sent(struct ptlrpc_bulk_desc *);
 int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *, int portal);
 int ptl_send_buf(struct ptlrpc_request *, struct lustre_peer *, int portal);
 int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *);
+int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *bulk);
 int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
                  struct ptlrpc_request *req);
 int ptlrpc_error(struct obd_device *obddev, struct ptlrpc_service *svc,
index c5dd013..94fb231 100644 (file)
 extern unsigned long obd_memory;
 extern unsigned long obd_fail_loc;
 
-enum {
-        OBD_FAIL_MDS = 0x100,
-        OBD_FAIL_MDS_HANDLE_UNPACK,
-        OBD_FAIL_MDS_GETATTR_NET,
-        OBD_FAIL_MDS_GETATTR_PACK,
-        OBD_FAIL_MDS_READPAGE_NET,
-        OBD_FAIL_MDS_READPAGE_PACK,
-        OBD_FAIL_MDS_SENDPAGE,
-        OBD_FAIL_MDS_REINT_NET,
-        OBD_FAIL_MDS_REINT_UNPACK,
-        OBD_FAIL_MDS_REINT_SETATTR,
-        OBD_FAIL_MDS_REINT_SETATTR_WRITE,
-        OBD_FAIL_MDS_REINT_CREATE,
-        OBD_FAIL_MDS_REINT_CREATE_WRITE,
-        OBD_FAIL_MDS_REINT_UNLINK,
-        OBD_FAIL_MDS_REINT_UNLINK_WRITE,
-        OBD_FAIL_MDS_REINT_LINK,
-        OBD_FAIL_MDS_REINT_LINK_WRITE,
-        OBD_FAIL_MDS_REINT_RENAME,
-        OBD_FAIL_MDS_REINT_RENAME_WRITE,
-        OBD_FAIL_MDS_OPEN_NET,
-        OBD_FAIL_MDS_OPEN_PACK,
-        OBD_FAIL_MDS_CLOSE_NET,
-        OBD_FAIL_MDS_CLOSE_PACK,
+#define OBD_FAIL_MDS                     0x100
+#define OBD_FAIL_MDS_HANDLE_UNPACK       0x101
+#define OBD_FAIL_MDS_GETATTR_NET         0x102
+#define OBD_FAIL_MDS_GETATTR_PACK        0x103
+#define OBD_FAIL_MDS_READPAGE_NET        0x104
+#define OBD_FAIL_MDS_READPAGE_PACK       0x105
+#define OBD_FAIL_MDS_SENDPAGE            0x106
+#define OBD_FAIL_MDS_REINT_NET           0x107
+#define OBD_FAIL_MDS_REINT_UNPACK        0x108
+#define OBD_FAIL_MDS_REINT_SETATTR       0x109
+#define OBD_FAIL_MDS_REINT_SETATTR_WRITE 0x10a
+#define OBD_FAIL_MDS_REINT_CREATE        0x10b
+#define OBD_FAIL_MDS_REINT_CREATE_WRITE  0x10c
+#define OBD_FAIL_MDS_REINT_UNLINK        0x10d
+#define OBD_FAIL_MDS_REINT_UNLINK_WRITE  0x10e
+#define OBD_FAIL_MDS_REINT_LINK          0x10f
+#define OBD_FAIL_MDS_REINT_LINK_WRITE    0x110
+#define OBD_FAIL_MDS_REINT_RENAME        0x111
+#define OBD_FAIL_MDS_REINT_RENAME_WRITE  0x112
+#define OBD_FAIL_MDS_OPEN_NET            0x113
+#define OBD_FAIL_MDS_OPEN_PACK           0x114
+#define OBD_FAIL_MDS_CLOSE_NET           0x115
+#define OBD_FAIL_MDS_CLOSE_PACK          0x116
 
-        OBD_FAIL_OST = 0x200,
-        OBD_FAIL_OST_CONNECT_NET,
-        OBD_FAIL_OST_DISCONNECT_NET,
-        OBD_FAIL_OST_GET_INFO_NET,
-        OBD_FAIL_OST_CREATE_NET,
-        OBD_FAIL_OST_DESTROY_NET,
-        OBD_FAIL_OST_GETATTR_NET,
-        OBD_FAIL_OST_SETATTR_NET,
-        OBD_FAIL_OST_OPEN_NET,
-        OBD_FAIL_OST_CLOSE_NET,
-        OBD_FAIL_OST_BRW_NET,
-        OBD_FAIL_OST_PUNCH_NET,
+#define OBD_FAIL_OST                     0x200
+#define OBD_FAIL_OST_CONNECT_NET         0x201
+#define OBD_FAIL_OST_DISCONNECT_NET      0x202
+#define OBD_FAIL_OST_GET_INFO_NET        0x203
+#define OBD_FAIL_OST_CREATE_NET          0x204
+#define OBD_FAIL_OST_DESTROY_NET         0x205
+#define OBD_FAIL_OST_GETATTR_NET         0x206
+#define OBD_FAIL_OST_SETATTR_NET         0x207
+#define OBD_FAIL_OST_OPEN_NET            0x208
+#define OBD_FAIL_OST_CLOSE_NET           0x209
+#define OBD_FAIL_OST_BRW_NET             0x20a
+#define OBD_FAIL_OST_PUNCH_NET           0x20b
 
-        OBB_FAIL_LDLM = 0x300,
-        OBD_FAIL_LDLM_ENQUEUE,
-        OBD_FAIL_LDLM_CONVERT,
-        OBD_FAIL_LDLM_CANCEL,
-        OBD_FAIL_LDLM_CALLBACK,
-
-};
+#define OBB_FAIL_LDLM                    0x300
+#define OBD_FAIL_LDLM_ENQUEUE            0x301
+#define OBD_FAIL_LDLM_CONVERT            0x302
+#define OBD_FAIL_LDLM_CANCEL             0x303
+#define OBD_FAIL_LDLM_CALLBACK           0x304
 
 /* preparation for a more advanced failure testbed (not functional yet) */
 #define OBD_FAIL_MASK_SYS    0x0000FF00
index 80397f6..e33d432 100644 (file)
@@ -60,8 +60,8 @@ void mds_create_pack(struct mds_rec_create *rec, struct inode *inode,
         }
 }
 
-
-void mds_setattr_pack(struct mds_rec_setattr *rec, struct inode *inode, struct iattr *iattr)
+void mds_setattr_pack(struct mds_rec_setattr *rec, struct inode *inode,
+                      struct iattr *iattr)
 {
         rec->sa_reclen = HTON__u32(sizeof(*rec));
         rec->sa_opcode = HTON__u32(REINT_SETATTR);
index 2a829d6..68ce977 100644 (file)
@@ -140,11 +140,11 @@ static struct super_block * ll_read_super(struct super_block *sb,
         connected = 1;
 
         /* the first parameter should become an mds device no */
-        err = ptlrpc_connect_client(-1, "mds", 
+        err = ptlrpc_connect_client(-1, "mds",
                                     MDS_REQUEST_PORTAL,
                                     MDC_REPLY_PORTAL,
                                     mds_pack_req,
-                                    mds_unpack_rep, 
+                                    mds_unpack_rep,
                                     &sbi->ll_mds_client);
         
         if (err) {
index 2bfdbb8..da630b4 100644 (file)
@@ -3,19 +3,19 @@
  *
  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
  *
- *   This file is part of Portals, http://www.sf.net/projects/lustre/
+ *   This file is part of Lustre, http://www.sf.net/projects/lustre/
  *
- *   Portals is free software; you can redistribute it and/or
+ *   Lustre is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   License as published by the Free Software Foundation.
  *
- *   Portals is distributed in the hope that it will be useful,
+ *   Lustre is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with Portals; if not, write to the Free Software
+ *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
index 18334a8..bf8b402 100644 (file)
@@ -3,19 +3,19 @@
  *
  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
  *
- *   This file is part of Portals, http://www.sf.net/projects/lustre/
+ *   This file is part of Lustre, http://www.sf.net/projects/lustre/
  *
- *   Portals is free software; you can redistribute it and/or
+ *   Lustre is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   License as published by the Free Software Foundation.
  *
- *   Portals is distributed in the hope that it will be useful,
+ *   Lustre is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with Portals; if not, write to the Free Software
+ *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
@@ -55,7 +55,7 @@
 extern int mds_queue_req(struct ptlrpc_request *);
 
 
-int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid, 
+int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid,
                 struct ptlrpc_request **req)
 {
         int rc;
@@ -63,18 +63,16 @@ int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid,
 
         ENTRY;
 
-        request = ptlrpc_prep_req(cl, MDS_GETATTR, 0, NULL, 0, NULL); 
-        if (!request) { 
+        request = ptlrpc_prep_req(cl, MDS_GETATTR, 0, NULL, 0, NULL);
+        if (!request) {
                 CERROR("llight request: cannot pack\n");
-                rc = -ENOMEM;
-                EXIT;
-                goto out;
+                GOTO(out, rc = -ENOMEM);
         }
 
         ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
 
         request->rq_req.mds->valid = valid;
-        request->rq_replen = 
+        request->rq_replen =
                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
 
         rc = ptlrpc_queue_wait(cl, request);
@@ -83,7 +81,7 @@ int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid,
         if (!rc)
                 CDEBUG(D_NET, "mode: %o\n", request->rq_rep.mds->mode);
 
-        EXIT;
+        GOTO(out, rc);
  out:
         *req = request;
         return rc;
@@ -93,10 +91,10 @@ int mdc_open(struct ptlrpc_client *cl, ino_t ino, int type, int flags,
              __u64 *fh, struct ptlrpc_request **req)
 {
         struct ptlrpc_request *request;
-        int rc; 
+        int rc;
 
-        request = ptlrpc_prep_req(cl, MDS_OPEN, 0, NULL, 0, NULL); 
-        if (!request) { 
+        request = ptlrpc_prep_req(cl, MDS_OPEN, 0, NULL, 0, NULL);
+        if (!request) {
                 CERROR("llight request: cannot pack\n");
                 rc = -ENOMEM;
                 goto out;
@@ -104,51 +102,51 @@ int mdc_open(struct ptlrpc_client *cl, ino_t ino, int type, int flags,
 
         ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
         request->rq_req.mds->flags = HTON__u32(flags);
-        request->rq_replen = 
+        request->rq_replen =
                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
 
         rc = ptlrpc_queue_wait(cl, request);
         rc = ptlrpc_check_status(request, rc);
 
-        if (rc) { 
-                CERROR("llight request: error in handling %d\n", rc); 
+        if (rc) {
+                CERROR("llight request: error in handling %d\n", rc);
                 goto out;
         }
 
-        *fh = request->rq_rep.mds->objid; 
- out: 
+        *fh = request->rq_rep.mds->objid;
+ out:
         *req = request;
         return rc;
 }
 
 
-int mdc_close(struct ptlrpc_client *cl, ino_t ino, int type, __u64 fh, 
+int mdc_close(struct ptlrpc_client *cl, ino_t ino, int type, __u64 fh,
               struct ptlrpc_request **req)
 {
         struct ptlrpc_request *request;
-        int rc; 
+        int rc;
 
-        request = ptlrpc_prep_req(cl, MDS_CLOSE, 0, NULL, 0, NULL); 
-        if (!request) { 
+        request = ptlrpc_prep_req(cl, MDS_CLOSE, 0, NULL, 0, NULL);
+        if (!request) {
                 CERROR("llight request: cannot pack\n");
                 rc = -ENOMEM;
                 goto out;
         }
 
         ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
-        request->rq_req.mds->objid = fh; 
-        request->rq_replen = 
+        request->rq_req.mds->objid = fh;
+        request->rq_replen =
                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
 
         rc = ptlrpc_queue_wait(cl, request);
         rc = ptlrpc_check_status(request, rc);
 
-        if (rc) { 
-                CERROR("llight request: error in handling %d\n", rc); 
+        if (rc) {
+                CERROR("llight request: error in handling %d\n", rc);
                 goto out;
         }
 
- out: 
+ out:
         *req = request;
         return rc;
 }
@@ -159,7 +157,7 @@ int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
         struct ptlrpc_request *request = NULL;
         struct ptlrpc_bulk_desc *bulk = NULL;
         struct niobuf niobuf;
-        int rc; 
+        int rc;
 
         niobuf.addr = (__u64) (long) addr;
 
@@ -174,7 +172,7 @@ int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
 
         request = ptlrpc_prep_req(cl, MDS_READPAGE, 0, NULL,
                                   sizeof(struct niobuf), (char *)&niobuf);
-        if (!request) { 
+        if (!request) {
                 CERROR("%s: cannot pack\n", __FUNCTION__);
                 rc = -ENOMEM;
                 goto out;
@@ -195,12 +193,13 @@ int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
         request->rq_req.mds->fid1.id = ino;
         request->rq_req.mds->fid1.f_type = type;
         request->rq_req.mds->size = offset;
-        request->rq_req.mds->tgtlen = sizeof(niobuf); 
+        request->rq_req.mds->tgtlen = sizeof(niobuf);
         request->rq_replen = sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
 
         rc = ptlrpc_queue_wait(cl, request);
-        if (rc) { 
-                CERROR("mdc request: error in handling %d\n", rc); 
+        if (rc) {
+                CERROR("mdc request: error in handling %d\n", rc);
+                ptlrpc_abort_bulk(bulk);
                 goto out;
         }
 
@@ -213,7 +212,7 @@ int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
         return rc;
 }
 
-static int request_ioctl(struct inode *inode, struct file *file, 
+static int request_ioctl(struct inode *inode, struct file *file,
                          unsigned int cmd, unsigned long arg)
 {
         int err;
@@ -222,88 +221,111 @@ static int request_ioctl(struct inode *inode, struct file *file,
 
         ENTRY;
 
-        if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
-                EXIT;
-                return -EINVAL;
-        }
+        if (MINOR(inode->i_rdev) != REQUEST_MINOR)
+                RETURN(-EINVAL);
 
-        if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE || 
-             _IOC_NR(cmd) < IOC_REQUEST_MIN_NR  || 
-             _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
+        if (_IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
+            _IOC_NR(cmd) < IOC_REQUEST_MIN_NR  ||
+            _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
                 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
-                                _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
-                EXIT;
-                return -EINVAL;
+                       _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
+                RETURN(-EINVAL);
         }
 
-        /* XXX complete this to get debugging working again */
-        err = -1;
+        err = ptlrpc_connect_client(-1, "mds",
+                                    MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
+                                    mds_pack_req, mds_unpack_rep, &cl);
         if (err) {
                 CERROR("cannot create client\n");
-                return -EINVAL;
+                RETURN(-EINVAL);
         }
-        
-        switch (cmd) {
-        case IOC_REQUEST_GETATTR: { 
-                CERROR("-- getting attr for ino 2\n"); 
-                err = mdc_getattr(&cl, 2, S_IFDIR, ~0, &request);
 
+        switch (cmd) {
+        case IOC_REQUEST_GETATTR: {
+                CERROR("-- getting attr for ino %lu\n", arg);
+                err = mdc_getattr(&cl, arg, S_IFDIR, ~0, &request);
                 CERROR("-- done err %d\n", err);
-                break;
+
+                GOTO(out, err);
         }
 
-        case IOC_REQUEST_READPAGE: { 
+        case IOC_REQUEST_READPAGE: {
                 char *buf;
                 OBD_ALLOC(buf, PAGE_SIZE);
-                if (!buf) { 
+                if (!buf) {
                         err = -ENOMEM;
                         break;
                 }
-                CERROR("-- readpage 0 for ino 2\n"); 
-                err = mdc_readpage(&cl, 2, S_IFDIR, 0, buf, &request);
+                CERROR("-- readpage 0 for ino %lu\n", arg);
+                err = mdc_readpage(&cl, arg, S_IFDIR, 0, buf, &request);
                 CERROR("-- done err %d\n", err);
                 OBD_FREE(buf, PAGE_SIZE);
-                break;
+
+                GOTO(out, err);
         }
 
-        case IOC_REQUEST_SETATTR: { 
+        case IOC_REQUEST_SETATTR: {
                 struct inode inode;
-                struct iattr iattr; 
+                struct iattr iattr;
 
-                inode.i_ino = 2;
+                inode.i_ino = arg;
+                inode.i_generation = 0;
                 iattr.ia_mode = 040777;
                 iattr.ia_atime = 0;
                 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
 
                 err = mdc_setattr(&cl, &inode, &iattr, &request);
                 CERROR("-- done err %d\n", err);
-                break;
+
+                GOTO(out, err);
         }
 
-        case IOC_REQUEST_CREATE: { 
+        case IOC_REQUEST_CREATE: {
                 struct inode inode;
-                struct iattr iattr; 
+                struct iattr iattr;
 
-                inode.i_ino = 2;
+                inode.i_ino = arg;
+                inode.i_generation = 0;
                 iattr.ia_mode = 040777;
                 iattr.ia_atime = 0;
                 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
 
-                err = mdc_create(&cl, &inode, 
-                                 "foofile", strlen("foofile"), 
-                                 NULL, 0, 0100707, 47114711, 
+                err = mdc_create(&cl, &inode,
+                                 "foofile", strlen("foofile"),
+                                 NULL, 0, 0100707, 47114711,
                                  11, 47, 0, &request);
                 CERROR("-- done err %d\n", err);
-                break;
+
+                GOTO(out, err);
+        }
+
+        case IOC_REQUEST_OPEN: {
+                __u64 fh, ino;
+                copy_from_user(&ino, (__u64 *)arg, sizeof(ino));
+                CERROR("-- opening ino %llu\n", ino);
+                err = mdc_open(&cl, ino, S_IFDIR, O_RDONLY, &fh, &request);
+                copy_to_user((__u64 *)arg, &fh, sizeof(fh));
+                CERROR("-- done err %d (fh=%Lu)\n", err, fh);
+
+                GOTO(out, err);
         }
 
-        default:                
-                err = -EINVAL;
-                EXIT;
-                break;
+        case IOC_REQUEST_CLOSE: {
+                CERROR("-- closing ino 2, filehandle %lu\n", arg);
+                err = mdc_close(&cl, 2, S_IFDIR, arg, &request);
+                CERROR("-- done err %d\n", err);
+
+                GOTO(out, err);
         }
-        EXIT;
-        return err;
+
+        default:
+                RETURN(-EINVAL);
+        }
+
+ out:
+        ptlrpc_free_req(request);
+
+        RETURN(err);
 }
 
 
@@ -311,21 +333,18 @@ static struct file_operations requestdev_fops = {
         ioctl: request_ioctl,
 };
 
-
 static struct miscdevice request_dev = {
         REQUEST_MINOR,
         "request",
         &requestdev_fops
 };
 
-
 static int __init ptlrpc_request_init(void)
 {
         misc_register(&request_dev);
-        return 0 ;
+        return 0;
 }
 
-
 static void __exit ptlrpc_request_exit(void)
 {
         misc_deregister(&request_dev);
@@ -335,13 +354,13 @@ MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
 MODULE_LICENSE("GPL");
 
-EXPORT_SYMBOL(mdc_create); 
-EXPORT_SYMBOL(mdc_unlink); 
-EXPORT_SYMBOL(mdc_rename); 
-EXPORT_SYMBOL(mdc_link); 
-EXPORT_SYMBOL(mdc_getattr); 
-EXPORT_SYMBOL(mdc_readpage); 
-EXPORT_SYMBOL(mdc_setattr); 
+EXPORT_SYMBOL(mdc_create);
+EXPORT_SYMBOL(mdc_unlink);
+EXPORT_SYMBOL(mdc_rename);
+EXPORT_SYMBOL(mdc_link);
+EXPORT_SYMBOL(mdc_getattr);
+EXPORT_SYMBOL(mdc_readpage);
+EXPORT_SYMBOL(mdc_setattr);
 EXPORT_SYMBOL(mdc_close);
 EXPORT_SYMBOL(mdc_open);
 
index 9f30016..2b79f26 100644 (file)
@@ -39,8 +39,6 @@ int mds_sendpage(struct ptlrpc_request *req, struct file *file,
         int rc = 0;
         mm_segment_t oldfs = get_fs();
 
-        OBD_FAIL_RETURN(OBD_FAIL_MDS_SENDPAGE, -EIO);
-
         if (req->rq_peer.peer_nid == 0) {
                 /* dst->addr is a user address, but in a different task! */
                 char *buf = (char *)(long)dst->addr;
@@ -87,6 +85,12 @@ int mds_sendpage(struct ptlrpc_request *req, struct file *file,
                 bulk->b_buflen = PAGE_SIZE;
 
                 rc = ptlrpc_send_bulk(bulk, MDS_BULK_PORTAL);
+                if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
+                        CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
+                               OBD_FAIL_MDS_SENDPAGE, rc);
+                        PtlMDUnlink(bulk->b_md_h);
+                        GOTO(cleanup_buf, rc);
+                }
                 wait_event_interruptible(bulk->b_waitq,
                                          ptlrpc_check_bulk_sent(bulk));
 
@@ -279,7 +283,6 @@ int mds_close(struct ptlrpc_request *req)
         return 0;
 }
 
-
 int mds_readpage(struct ptlrpc_request *req)
 {
         struct vfsmount *mnt;
@@ -385,6 +388,9 @@ int mds_handle(struct obd_device *dev, struct ptlrpc_service *svc,
                 CDEBUG(D_INODE, "readpage\n");
                 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
                 rc = mds_readpage(req);
+
+                if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
+                        return 0;
                 break;
 
         case MDS_REINT:
index 1339293..e963d55 100644 (file)
@@ -138,7 +138,6 @@ struct ptlrpc_request *ptlrpc_prep_req(struct ptlrpc_client *cl,
         }
 
         memset(request, 0, sizeof(*request));
-        //spin_lock_init(&request->rq_lock);
 
         spin_lock(&cl->cli_lock);
         request->rq_xid = cl->cli_xid++;
@@ -227,12 +226,10 @@ int ptlrpc_abort(struct ptlrpc_request *request)
 {
         /* First remove the ME for the reply; in theory, this means
          * that we can tear down the buffer safely. */
-        //spin_lock(&request->rq_lock);
         PtlMEUnlink(request->rq_reply_me_h);
-        OBD_FREE(request->rq_repbuf, request->rq_replen);
+        OBD_FREE(request->rq_reply_md.start, request->rq_replen);
         request->rq_repbuf = NULL;
         request->rq_replen = 0;
-        //spin_unlock(&request->rq_lock);
 
         return 0;
 }
index fc97e3a..3289447 100644 (file)
@@ -50,8 +50,7 @@ static int sent_packet_callback(ptl_event_t *ev, void *data)
                 LBUG();
         }
 
-        EXIT;
-        return 1;
+        RETURN(1);
 }
 
 /*
@@ -72,8 +71,7 @@ static int rcvd_reply_callback(ptl_event_t *ev, void *data)
                 LBUG();
         }
 
-        EXIT;
-        return 1;
+        RETURN(1);
 }
 
 int server_request_callback(ptl_event_t *ev, void *data)
index 74bff81..0e5bb32 100644 (file)
@@ -119,7 +119,6 @@ int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *bulk, int portal)
 {
         int rc;
         ptl_process_id_t remote_id;
-        ptl_handle_md_t md_h;
 
         bulk->b_md.start = bulk->b_buf;
         bulk->b_md.length = bulk->b_buflen;
@@ -128,7 +127,7 @@ int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *bulk, int portal)
         bulk->b_md.options = PTL_MD_OP_PUT;
         bulk->b_md.user_ptr = bulk;
 
-        rc = PtlMDBind(bulk->b_peer.peer_ni, bulk->b_md, &md_h);
+        rc = PtlMDBind(bulk->b_peer.peer_ni, bulk->b_md, &bulk->b_md_h);
         if (rc != 0) {
                 CERROR("PtlMDBind failed: %d\n", rc);
                 LBUG();
@@ -141,11 +140,12 @@ int ptlrpc_send_bulk(struct ptlrpc_bulk_desc *bulk, int portal)
         CDEBUG(D_NET, "Sending %d bytes to portal %d, xid %d\n",
                bulk->b_md.length, portal, bulk->b_xid);
 
-        rc = PtlPut(md_h, PTL_ACK_REQ, remote_id, portal, 0, bulk->b_xid, 0, 0);
+        rc = PtlPut(bulk->b_md_h, PTL_ACK_REQ, remote_id, portal, 0,
+                    bulk->b_xid, 0, 0);
         if (rc != PTL_OK) {
                 CERROR("PtlPut(%d, %d, %d) failed: %d\n", remote_id.nid,
                        portal, bulk->b_xid, rc);
-                PtlMDUnlink(md_h);
+                PtlMDUnlink(bulk->b_md_h);
                 LBUG();
         }
 
@@ -164,8 +164,7 @@ int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *bulk)
         if (rc != PTL_OK) {
                 CERROR("PtlMEAttach failed: %d\n", rc);
                 LBUG();
-                EXIT;
-                goto cleanup1;
+                GOTO(cleanup, rc);
         }
 
         bulk->b_md.start = bulk->b_buf;
@@ -180,23 +179,30 @@ int ptlrpc_register_bulk(struct ptlrpc_bulk_desc *bulk)
         if (rc != PTL_OK) {
                 CERROR("PtlMDAttach failed: %d\n", rc);
                 LBUG();
-                EXIT;
-                goto cleanup2;
+                GOTO(cleanup, rc);
         }
 
         CDEBUG(D_NET, "Setup bulk sink buffer: %u bytes, xid %u, portal %u\n",
                bulk->b_buflen, bulk->b_xid, bulk->b_portal);
-        EXIT;
-        return 0;
+        RETURN(0);
 
         // XXX Confirm that this is safe!
- cleanup2:
-        PtlMDUnlink(bulk->b_md_h);
- cleanup1:
+ cleanup:
         PtlMEUnlink(bulk->b_me_h);
         return rc;
 }
 
+int ptlrpc_abort_bulk(struct ptlrpc_bulk_desc *bulk)
+{
+        int rc;
+
+        rc = PtlMEUnlink(bulk->b_me_h);
+        if (rc != PTL_OK)
+                CERROR("PtlMEUnlink failed: %d\n", rc);
+
+        return rc;
+}
+
 int ptlrpc_reply(struct obd_device *obddev, struct ptlrpc_service *svc,
                  struct ptlrpc_request *req)
 {
@@ -275,20 +281,18 @@ int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl)
         if (NTOH__u32(hdr->type) != PTL_RPC_REQUEST) {
                 CERROR("wrong packet type sent %d\n", NTOH__u32(hdr->type));
                 LBUG();
+                RETURN(-EINVAL);
         }
         if (request->rq_replen == 0) {
                 CERROR("request->rq_replen is 0!\n");
-                EXIT;
-                return -EINVAL;
+                RETURN(-EINVAL);
         }
 
         /* request->rq_repbuf is set only when the reply comes in, in
          * client_packet_callback() */
         OBD_ALLOC(repbuf, request->rq_replen);
-        if (!repbuf) { 
-                EXIT;
-                return -ENOMEM;
-        }
+        if (!repbuf)
+                RETURN(-ENOMEM);
 
         local_id.nid = PTL_ID_ANY;
         local_id.pid = PTL_ID_ANY;
@@ -301,8 +305,7 @@ int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl)
         if (rc != PTL_OK) {
                 CERROR("PtlMEAttach failed: %d\n", rc);
                 LBUG();
-                EXIT;
-                goto cleanup;
+                GOTO(cleanup, rc);
         }
 
         request->rq_type = PTL_RPC_REQUEST;
@@ -318,14 +321,14 @@ int ptl_send_rpc(struct ptlrpc_request *request, struct ptlrpc_client *cl)
         if (rc != PTL_OK) {
                 CERROR("PtlMDAttach failed: %d\n", rc);
                 LBUG();
-                EXIT;
-                goto cleanup2;
+                GOTO(cleanup2, rc);
         }
 
         CDEBUG(D_NET, "Setup reply buffer: %u bytes, xid %u, portal %u\n",
                request->rq_replen, request->rq_xid, request->rq_reply_portal);
 
-        return ptl_send_buf(request, &cl->cli_server, request->rq_req_portal);
+        rc = ptl_send_buf(request, &cl->cli_server, request->rq_req_portal);
+        RETURN(rc);
 
  cleanup2:
         PtlMEUnlink(request->rq_reply_me_h);
index e17c139..fc24eb2 100644 (file)
@@ -3,19 +3,16 @@
 SRCDIR="`dirname $0`"
 . $SRCDIR/common.sh
 
-setup
+NETWORK=tcp
+LOCALHOST=localhost
+SERVER=localhost
+PORT=1234
 
-$PTLCTL <<EOF
-mynid localhost
-setup tcp
-connect localhost 1234
-add_uuid self
-add_uuid mds
-quit
-EOF
+setup
+setup_portals
 
 MDSFS=ext2
-new_fs ${MDSFS} /tmp/mds 10000
+new_fs ${MDSFS} /tmp/mds 1000
 MDS=$LOOPDEV
 
 echo 0xffffffff > /proc/sys/portals/debug
@@ -28,4 +25,12 @@ quit
 EOF
 
 mknod /dev/request c 10 244
-# $R/usr/src/obd/tests/testreq
+
+./testreq --getattr
+./testreq --setattr
+./testreq --readpage
+./testreq --open
+./testreq --close junk_file_handle
+./testreq --create
+
+echo "Done."
index 29d2a39..0da22bc 100755 (executable)
@@ -7,7 +7,7 @@ run() {
        shift
        $* &
        sleep 1
-       kill $!
+       kill -9 $!
 }
 
 # GETATTR_NET - ls will hang on the getattr
@@ -16,6 +16,8 @@ run 0x102 ls /mnt/obd/lost+found
 # READPAGE_NET - ls will hang reading in new pages (lost+found is not in cache)
 run 0x104 ls /mnt/obd/lost+found
 
+sleep 1
+
 # REINT_NET - touch will hang on setattr
 run 0x107 touch /mnt/obd
 
@@ -29,9 +31,11 @@ run 0x107 mv /mnt/obd/lost+found /mnt/obd/lost
 run 0x107 rmdir /mnt/obd/lost+found
 
 # OPEN_NET - ls will hang on open
-run 0x107 ls /mnt/obd/lost+found
+run 0x113 ls /mnt/obd/lost+found
 
 # CLOSE_NET - ls will hang on close
-run 0x107 ls /mnt/obd/lost+found
+run 0x115 ./testreq --close junk_file_handle
+
+run 0 ls -a /mnt/obd/
 
-run 0 ls -a /mnt/obd/lost+found
+echo "Done."
\ No newline at end of file
index aeacddf..8580a58 100644 (file)
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ * Copyright (C) 2002 Cluster File Systems, Inc.
+ *
+ *   This file is part of Lustre, http://www.sf.net/projects/lustre/
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
 #include <stdio.h>
-#include <sys/ioctl.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+#undef _GNU_SOURCE
+
+#include <linux/lustre_mds.h>
+
+static void usage(char *argv0, int status)
+{
+        printf(
+"Usage: %s [OPTION...]\n\
+\n\
+--getattr <directory>\n\
+--setattr <directory>\n\
+--readpage <directory>\n\
+--open <directory>\n\
+--close <directory handle (returned by open)>\n\
+--create <new name>\n", argv0);
 
-#define IOC_REQUEST_GETATTR            _IOWR('f', 30, long)
-#define IOC_REQUEST_READPAGE           _IOWR('f', 31, long)
-#define IOC_REQUEST_SETATTR            _IOWR('f', 32, long)
-#define IOC_REQUEST_CREATE             _IOWR('f', 33, long)
+        exit(status);
+}
 
 int main(int argc, char **argv)
 {
-       int fd, rc; 
-       int cmd = IOC_REQUEST_GETATTR;
-
-       printf("ioctl type %d, nr %d size %d\n", 
-              _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
-
-       fd = open("/dev/request", O_RDONLY);
-       if (fd == -1) { 
-               printf("error opening /dev/request: %s\n", strerror(errno));
-               return 1;
-       }
-
-       printf("getattr test... ");
-       rc = ioctl(fd, IOC_REQUEST_GETATTR, NULL); 
-       printf("result: %d\n", rc); 
-
-       printf("readpage test... ");
-       rc = ioctl(fd, IOC_REQUEST_READPAGE, NULL); 
-       printf("result: %d\n", rc); 
-
-       printf("setattr test... ");
-       rc = ioctl(fd, IOC_REQUEST_SETATTR, NULL); 
-       printf("result: %d\n", rc); 
-
-       printf("create test... ");
-       rc = ioctl(fd, IOC_REQUEST_CREATE, NULL); 
-       printf("result: %d\n", rc); 
-       return 0;
+        int fd, rc, c, cmd = 0;
+        unsigned long arg;
+        char *short_opts = "h", *name;
+        static struct option long_opts[] = {
+#define OPT_GETATTR -2
+                {"getattr", no_argument, NULL, OPT_GETATTR},
+#define OPT_READPAGE -3
+                {"readpage", no_argument, NULL, OPT_READPAGE},
+#define OPT_SETATTR -4
+                {"setattr", no_argument, NULL, OPT_SETATTR},
+#define OPT_CREATE -5
+                {"create", no_argument, NULL, OPT_CREATE},
+#define OPT_OPEN -6
+                {"open", no_argument, NULL, OPT_OPEN},
+#define OPT_CLOSE -7
+                {"close", required_argument, NULL, OPT_CLOSE},
+#define OPT_HELP 'h'
+                {"help", no_argument, NULL, OPT_HELP},
+                {0}
+        };
+
+        do {
+                c = getopt_long(argc, argv, short_opts, long_opts, NULL);
+
+                switch (c) {
+                case OPT_HELP:
+                        usage(argv[0], 0);
+                        break;
+                case OPT_GETATTR:
+                        cmd = IOC_REQUEST_GETATTR;
+                        name = "getattr";
+                        arg = 2;
+                        break;
+                case OPT_SETATTR:
+                        cmd = IOC_REQUEST_SETATTR;
+                        name = "setattr";
+                        arg = 2;
+                        break;
+                case OPT_READPAGE:
+                        cmd = IOC_REQUEST_READPAGE;
+                        name = "readpage";
+                        arg = 2;
+                        break;
+                case OPT_CREATE:
+                        cmd = IOC_REQUEST_CREATE;
+                        name ="create";
+                        arg = 2;
+                        break;
+                case OPT_OPEN:
+                        cmd = IOC_REQUEST_OPEN;
+                        name = "open";
+                        arg = 2;
+                        break;
+                case OPT_CLOSE:
+                        cmd = IOC_REQUEST_CLOSE;
+                        name = "close";
+                        arg = strtoul(optarg, NULL, 0);
+                        break;
+                case '?':
+                        usage(argv[0], 1);
+                        break;
+                }
+        } while (c != -1);
+
+        if (cmd == 0)
+                usage(argv[0], 1);
+
+        fd = open("/dev/request", O_RDONLY);
+        if (fd == -1) {
+                fprintf(stderr, "error opening /dev/request: %s\n",
+                        strerror(errno));
+                exit(1);
+        }
+
+        fprintf(stderr, "Executing %s test (arg=%lu)...\n", name, arg);
+        if (cmd == IOC_REQUEST_OPEN) {
+                rc = ioctl(fd, cmd, &arg);
+                printf("%lu\n", arg);
+        } else
+                rc = ioctl(fd, cmd, arg);
+        fprintf(stderr, "result code: %d\n", rc);
+
+        return 0;
 }