Whamcloud - gitweb
LU-3030 build: Update Master Copyrights pre 2.4 split
[fs/lustre-release.git] / lustre / mdc / mdc_lib.c
index 4d7cdf2..1e86153 100644 (file)
@@ -1,25 +1,37 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- *  Copyright (c) 2003 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * This program 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 version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source 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.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   In either case, 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
- *   license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2013, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_MDC
@@ -27,8 +39,8 @@
 # include <fcntl.h>
 # include <liblustre.h>
 #endif
-#include <lustre/lustre_idl.h>
 #include <lustre_net.h>
+#include <lustre/lustre_idl.h>
 #include "mdc_internal.h"
 
 #ifndef __KERNEL__
@@ -43,11 +55,11 @@ static void __mdc_pack_body(struct mdt_body *b, __u32 suppgid)
         LASSERT (b != NULL);
 
         b->suppgid = suppgid;
-        b->uid = current->uid;
-        b->gid = current->gid;
-        b->fsuid = current->fsuid;
-        b->fsgid = current->fsgid;
-        b->capability = current->cap_effective;
+        b->uid = cfs_curproc_uid();
+        b->gid = cfs_curproc_gid();
+        b->fsuid = cfs_curproc_fsuid();
+        b->fsgid = cfs_curproc_fsgid();
+        b->capability = cfs_curproc_cap_pack();
 }
 
 void mdc_pack_capa(struct ptlrpc_request *req, const struct req_msg_field *field,
@@ -82,6 +94,21 @@ void mdc_is_subdir_pack(struct ptlrpc_request *req, const struct lu_fid *pfid,
         b->flags = flags;
 }
 
+void mdc_swap_layouts_pack(struct ptlrpc_request *req,
+                          struct md_op_data *op_data)
+{
+       struct mdt_body *b = req_capsule_client_get(&req->rq_pill,
+                                                   &RMF_MDT_BODY);
+
+       __mdc_pack_body(b, op_data->op_suppgids[0]);
+       b->fid1 = op_data->op_fid1;
+       b->fid2 = op_data->op_fid2;
+       b->valid |= OBD_MD_FLID;
+
+       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
+       mdc_pack_capa(req, &RMF_CAPA2, op_data->op_capa2);
+}
+
 void mdc_pack_body(struct ptlrpc_request *req,
                    const struct lu_fid *fid, struct obd_capa *oc,
                    __u64 valid, int ea_size, __u32 suppgid, int flags)
@@ -110,51 +137,59 @@ void mdc_readdir_pack(struct ptlrpc_request *req, __u64 pgoff,
         b->size = pgoff;                       /* !! */
         b->nlink = size;                        /* !! */
         __mdc_pack_body(b, -1);
+        b->mode = LUDA_FID | LUDA_TYPE;
+
         mdc_pack_capa(req, &RMF_CAPA1, oc);
 }
 
 /* packing of MDS records */
 void mdc_create_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
                      const void *data, int datalen, __u32 mode,
-                     __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev)
+                     __u32 uid, __u32 gid, cfs_cap_t cap_effective, __u64 rdev)
 {
-        struct mdt_rec_create *rec;
-        char                  *tmp;
-
-        CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create));
-        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
-
-
-        rec->cr_opcode   = REINT_CREATE;
-        rec->cr_fsuid    = uid;
-        rec->cr_fsgid    = gid;
-        rec->cr_cap      = cap_effective;
-        rec->cr_fid1     = op_data->op_fid1;
-        rec->cr_fid2     = op_data->op_fid2;
-        rec->cr_mode     = mode;
-        rec->cr_rdev     = rdev;
-        rec->cr_time     = op_data->op_mod_time;
-        rec->cr_suppgid1 = op_data->op_suppgids[0];
-        rec->cr_suppgid2 = op_data->op_suppgids[1];
-        rec->cr_flags    = op_data->op_flags & ~MF_SOM_LOCAL_FLAGS;
-        rec->cr_bias     = op_data->op_bias;
-
-        mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-
-        tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
-        LOGL0(op_data->op_name, op_data->op_namelen, tmp);
-
-        if (data) {
-                tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
-                memcpy(tmp, data, datalen);
-        }
+       struct mdt_rec_create   *rec;
+       char                    *tmp;
+       __u64                    flags;
+
+       CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create));
+       rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
+
+
+       rec->cr_opcode   = REINT_CREATE;
+       rec->cr_fsuid    = uid;
+       rec->cr_fsgid    = gid;
+       rec->cr_cap      = cap_effective;
+       rec->cr_fid1     = op_data->op_fid1;
+       rec->cr_fid2     = op_data->op_fid2;
+       rec->cr_mode     = mode;
+       rec->cr_rdev     = rdev;
+       rec->cr_time     = op_data->op_mod_time;
+       rec->cr_suppgid1 = op_data->op_suppgids[0];
+       rec->cr_suppgid2 = op_data->op_suppgids[1];
+       flags = op_data->op_flags & MF_SOM_LOCAL_FLAGS;
+       if (op_data->op_bias & MDS_CREATE_VOLATILE)
+               flags |= MDS_OPEN_VOLATILE;
+       set_mrc_cr_flags(rec, flags);
+       rec->cr_bias     = op_data->op_bias;
+       rec->cr_umask    = cfs_curproc_umask();
+
+       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
+
+       tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
+       LOGL0(op_data->op_name, op_data->op_namelen, tmp);
+
+       if (data) {
+               tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
+               memcpy(tmp, data, datalen);
+       }
 }
 
-static __u32 mds_pack_open_flags(__u32 flags)
+static __u64 mds_pack_open_flags(__u32 flags, __u32 mode)
 {
-        __u32 cr_flags = (flags & (FMODE_READ | FMODE_WRITE |
-                                   MDS_OPEN_HAS_EA | MDS_OPEN_HAS_OBJS | 
-                                   MDS_OPEN_OWNEROVERRIDE | MDS_OPEN_LOCK));
+       __u64 cr_flags = (flags & (FMODE_READ | FMODE_WRITE |
+                                  MDS_OPEN_HAS_EA | MDS_OPEN_HAS_OBJS |
+                                  MDS_OPEN_OWNEROVERRIDE | MDS_OPEN_LOCK |
+                                  MDS_OPEN_BY_FID));
         if (flags & O_CREAT)
                 cr_flags |= MDS_OPEN_CREAT;
         if (flags & O_EXCL)
@@ -167,8 +202,6 @@ static __u32 mds_pack_open_flags(__u32 flags)
                 cr_flags |= MDS_OPEN_SYNC;
         if (flags & O_DIRECTORY)
                 cr_flags |= MDS_OPEN_DIRECTORY;
-        if (flags & O_JOIN_FILE)
-                cr_flags |= MDS_OPEN_JOIN_FILE;
 #ifdef FMODE_EXEC
         if (flags & FMODE_EXEC)
                 cr_flags |= MDS_FMODE_EXEC;
@@ -176,67 +209,63 @@ static __u32 mds_pack_open_flags(__u32 flags)
         if (flags & O_LOV_DELAY_CREATE)
                 cr_flags |= MDS_OPEN_DELAY_CREATE;
 
+        if ((flags & O_NOACCESS) || (flags & O_NONBLOCK))
+                cr_flags |= MDS_OPEN_NORESTORE;
+
         return cr_flags;
 }
 
 /* packing of MDS records */
-void mdc_join_pack(struct ptlrpc_request *req,
-                   struct md_op_data *op_data,
-                   __u64 head_size)
-{
-        struct mdt_rec_join *rec;
-
-        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_JOINFILE);
-        LASSERT(rec != NULL);
-        rec->jr_fid = op_data->op_fid2;
-        rec->jr_headsize = head_size;
-}
-
 void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
-                   __u32 mode, __u64 rdev, __u32 flags, const void *lmm,
-                   int lmmlen)
+                  __u32 mode, __u64 rdev, __u32 flags, const void *lmm,
+                  int lmmlen)
 {
-        struct mdt_rec_create *rec;
-        char *tmp;
-
-        CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create));
-        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
-
-        /* XXX do something about time, uid, gid */
-        rec->cr_opcode   = REINT_OPEN;
-        rec->cr_fsuid    = current->fsuid;
-        rec->cr_fsgid    = current->fsgid;
-        rec->cr_cap      = current->cap_effective;
-        if (op_data != NULL) {
-                rec->cr_fid1 = op_data->op_fid1;
-                rec->cr_fid2 = op_data->op_fid2;
-        }
-        rec->cr_mode     = mode;
-        rec->cr_flags    = mds_pack_open_flags(flags);
-        rec->cr_rdev     = rdev;
-        rec->cr_time     = op_data->op_mod_time;
-        rec->cr_suppgid1 = op_data->op_suppgids[0];
-        rec->cr_suppgid2 = op_data->op_suppgids[1];
-        rec->cr_bias     = op_data->op_bias;
-
-        mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-        /* the next buffer is child capa, which is used for replay,
-         * will be packed from the data in reply message. */
-
-        if (op_data->op_name) {
-                tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
-                LOGL0(op_data->op_name, op_data->op_namelen, tmp);
-        }
-
-        if (lmm) {
-                rec->cr_flags |= MDS_OPEN_HAS_EA;
+       struct mdt_rec_create *rec;
+       char *tmp;
+       __u64 cr_flags;
+
+       CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create));
+       rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
+
+       /* XXX do something about time, uid, gid */
+       rec->cr_opcode   = REINT_OPEN;
+       rec->cr_fsuid   = cfs_curproc_fsuid();
+       rec->cr_fsgid   = cfs_curproc_fsgid();
+       rec->cr_cap      = cfs_curproc_cap_pack();
+       if (op_data != NULL) {
+               rec->cr_fid1 = op_data->op_fid1;
+               rec->cr_fid2 = op_data->op_fid2;
+       }
+       rec->cr_mode     = mode;
+       cr_flags = mds_pack_open_flags(flags, mode);
+       rec->cr_rdev     = rdev;
+       rec->cr_time     = op_data->op_mod_time;
+       rec->cr_suppgid1 = op_data->op_suppgids[0];
+       rec->cr_suppgid2 = op_data->op_suppgids[1];
+       rec->cr_bias     = op_data->op_bias;
+       rec->cr_umask    = cfs_curproc_umask();
+
+       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
+       /* the next buffer is child capa, which is used for replay,
+        * will be packed from the data in reply message. */
+
+       if (op_data->op_name) {
+               tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
+               LOGL0(op_data->op_name, op_data->op_namelen, tmp);
+               if (op_data->op_bias & MDS_CREATE_VOLATILE)
+                       cr_flags |= MDS_OPEN_VOLATILE;
+       }
+
+       if (lmm) {
+               cr_flags |= MDS_OPEN_HAS_EA;
 #ifndef __KERNEL__
-                /*XXX a hack for liblustre to set EA (LL_IOC_LOV_SETSTRIPE) */
-                rec->cr_fid2 = op_data->op_fid2;
+               /*XXX a hack for liblustre to set EA (LL_IOC_LOV_SETSTRIPE) */
+               rec->cr_fid2 = op_data->op_fid2;
 #endif
-                tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
-                memcpy (tmp, lmm, lmmlen);
-        }
+               tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
+               memcpy(tmp, lmm, lmmlen);
+       }
+       set_mrc_cr_flags(rec, cr_flags);
 }
 
 static inline __u64 attr_pack(unsigned int ia_valid) {
@@ -274,8 +303,6 @@ static inline __u64 attr_pack(unsigned int ia_valid) {
                 sa_valid |= MDS_ATTR_FROM_OPEN;
         if (ia_valid & ATTR_BLOCKS)
                 sa_valid |= MDS_ATTR_BLOCKS;
-        if (ia_valid & ATTR_TRUNC)
-                sa_valid |= MDS_ATTR_TRUNC;
         if (ia_valid & MDS_OPEN_OWNEROVERRIDE)
                 /* NFSD hack (see bug 5781) */
                 sa_valid |= MDS_OPEN_OWNEROVERRIDE;
@@ -286,9 +313,9 @@ static void mdc_setattr_pack_rec(struct mdt_rec_setattr *rec,
                                  struct md_op_data *op_data)
 {
         rec->sa_opcode  = REINT_SETATTR;
-        rec->sa_fsuid   = current->fsuid;
-        rec->sa_fsgid   = current->fsgid;
-        rec->sa_cap     = current->cap_effective;
+        rec->sa_fsuid   = cfs_curproc_fsuid();
+        rec->sa_fsgid   = cfs_curproc_fsgid();
+        rec->sa_cap     = cfs_curproc_cap_pack();
         rec->sa_suppgid = -1;
 
         rec->sa_fid    = op_data->op_fid1;
@@ -303,25 +330,29 @@ static void mdc_setattr_pack_rec(struct mdt_rec_setattr *rec,
         rec->sa_ctime  = LTIME_S(op_data->op_attr.ia_ctime);
         rec->sa_attr_flags = ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
         if ((op_data->op_attr.ia_valid & ATTR_GID) &&
-            in_group_p(op_data->op_attr.ia_gid))
+            cfs_curproc_is_in_groups(op_data->op_attr.ia_gid))
                 rec->sa_suppgid = op_data->op_attr.ia_gid;
         else
                 rec->sa_suppgid = op_data->op_suppgids[0];
+
+       rec->sa_bias = op_data->op_bias;
 }
 
-static void mdc_epoch_pack(struct mdt_epoch *epoch, struct md_op_data *op_data)
+static void mdc_ioepoch_pack(struct mdt_ioepoch *epoch,
+                             struct md_op_data *op_data)
 {
         memcpy(&epoch->handle, &op_data->op_handle, sizeof(epoch->handle));
         epoch->ioepoch = op_data->op_ioepoch;
-        epoch->flags = op_data->op_flags & ~MF_SOM_LOCAL_FLAGS;
+        epoch->flags = op_data->op_flags & MF_SOM_LOCAL_FLAGS;
 }
 
 void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
                       void *ea, int ealen, void *ea2, int ea2len)
 {
         struct mdt_rec_setattr *rec;
-        struct mdt_epoch *epoch;
-        
+        struct mdt_ioepoch *epoch;
+        struct lov_user_md *lum = NULL;
+
         CLASSERT(sizeof(struct mdt_rec_reint) ==sizeof(struct mdt_rec_setattr));
         rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
         mdc_setattr_pack_rec(rec, op_data);
@@ -330,13 +361,21 @@ void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
 
         if (op_data->op_flags & (MF_SOM_CHANGE | MF_EPOCH_OPEN)) {
                 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
-                mdc_epoch_pack(epoch, op_data);
+                mdc_ioepoch_pack(epoch, op_data);
         }
 
         if (ealen == 0)
                 return;
 
-        memcpy(req_capsule_client_get(&req->rq_pill, &RMF_EADATA), ea, ealen);
+        lum = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
+        if (ea == NULL) { /* Remove LOV EA */
+                lum->lmm_magic = LOV_USER_MAGIC_V1;
+                lum->lmm_stripe_size = 0;
+                lum->lmm_stripe_count = 0;
+                lum->lmm_stripe_offset = (typeof(lum->lmm_stripe_offset))(-1);
+        } else {
+                memcpy(lum, ea, ealen);
+        }
 
         if (ea2len == 0)
                 return;
@@ -347,14 +386,15 @@ void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
 
 void mdc_unlink_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
 {
-        struct mdt_rec_unlink *rec;
-        char *tmp;
-        CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_unlink));
-        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
-        LASSERT (rec != NULL);
+       struct mdt_rec_unlink *rec;
+       char *tmp;
+
+       CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_unlink));
+       rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
+       LASSERT(rec != NULL);
 
-        rec->ul_opcode  = REINT_UNLINK;
+       rec->ul_opcode  = op_data->op_cli_flags & CLI_RM_ENTRY ?
+                                       REINT_RMENTRY : REINT_UNLINK;
         rec->ul_fsuid   = op_data->op_fsuid;
         rec->ul_fsgid   = op_data->op_fsgid;
         rec->ul_cap     = op_data->op_cap;
@@ -435,21 +475,19 @@ void mdc_rename_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
 }
 
 void mdc_getattr_pack(struct ptlrpc_request *req, __u64 valid, int flags,
-                      struct md_op_data *op_data)
+                      struct md_op_data *op_data, int ea_size)
 {
         struct mdt_body *b = req_capsule_client_get(&req->rq_pill,
                                                     &RMF_MDT_BODY);
 
-        b->fsuid = current->fsuid;
-        b->fsgid = current->fsgid;
-        b->capability = current->cap_effective;
         b->valid = valid;
         if (op_data->op_bias & MDS_CHECK_SPLIT)
                 b->valid |= OBD_MD_FLCKSPLIT;
         if (op_data->op_bias & MDS_CROSS_REF)
                 b->valid |= OBD_MD_FLCROSSREF;
-        b->flags = flags | MDS_BFLAG_EXT_FLAGS;
-        b->suppgid = op_data->op_suppgids[0];
+        b->eadatasize = ea_size;
+        b->flags = flags;
+        __mdc_pack_body(b, op_data->op_suppgids[0]);
 
         b->fid1 = op_data->op_fid1;
         b->fid2 = op_data->op_fid2;
@@ -466,7 +504,7 @@ void mdc_getattr_pack(struct ptlrpc_request *req, __u64 valid, int flags,
 
 void mdc_close_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
 {
-        struct mdt_epoch *epoch;
+        struct mdt_ioepoch *epoch;
         struct mdt_rec_setattr *rec;
 
         epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
@@ -474,59 +512,67 @@ void mdc_close_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
 
         mdc_setattr_pack_rec(rec, op_data);
         mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-        mdc_epoch_pack(epoch, op_data);
+        mdc_ioepoch_pack(epoch, op_data);
 }
 
 static int mdc_req_avail(struct client_obd *cli, struct mdc_cache_waiter *mcw)
 {
         int rc;
         ENTRY;
-        spin_lock(&cli->cl_loi_list_lock);
-        rc = list_empty(&mcw->mcw_entry);
-        spin_unlock(&cli->cl_loi_list_lock);
+        client_obd_list_lock(&cli->cl_loi_list_lock);
+        rc = cfs_list_empty(&mcw->mcw_entry);
+        client_obd_list_unlock(&cli->cl_loi_list_lock);
         RETURN(rc);
 };
 
 /* We record requests in flight in cli->cl_r_in_flight here.
  * There is only one write rpc possible in mdc anyway. If this to change
  * in the future - the code may need to be revisited. */
-void mdc_enter_request(struct client_obd *cli)
+int mdc_enter_request(struct client_obd *cli)
 {
+        int rc = 0;
         struct mdc_cache_waiter mcw;
-        struct l_wait_info lwi = { 0 };
+        struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
 
-        spin_lock(&cli->cl_loi_list_lock);
+        client_obd_list_lock(&cli->cl_loi_list_lock);
         if (cli->cl_r_in_flight >= cli->cl_max_rpcs_in_flight) {
-                list_add_tail(&mcw.mcw_entry, &cli->cl_cache_waiters);
+                cfs_list_add_tail(&mcw.mcw_entry, &cli->cl_cache_waiters);
                 cfs_waitq_init(&mcw.mcw_waitq);
-                spin_unlock(&cli->cl_loi_list_lock);
-                l_wait_event(mcw.mcw_waitq, mdc_req_avail(cli, &mcw), &lwi);
+                client_obd_list_unlock(&cli->cl_loi_list_lock);
+                rc = l_wait_event(mcw.mcw_waitq, mdc_req_avail(cli, &mcw), &lwi);
+                if (rc) {
+                        client_obd_list_lock(&cli->cl_loi_list_lock);
+                        if (cfs_list_empty(&mcw.mcw_entry))
+                                cli->cl_r_in_flight--;
+                        cfs_list_del_init(&mcw.mcw_entry);
+                        client_obd_list_unlock(&cli->cl_loi_list_lock);
+                }
         } else {
                 cli->cl_r_in_flight++;
-                spin_unlock(&cli->cl_loi_list_lock);
+                client_obd_list_unlock(&cli->cl_loi_list_lock);
         }
+        return rc;
 }
 
 void mdc_exit_request(struct client_obd *cli)
 {
-        struct list_head *l, *tmp;
+        cfs_list_t *l, *tmp;
         struct mdc_cache_waiter *mcw;
 
-        spin_lock(&cli->cl_loi_list_lock);
+        client_obd_list_lock(&cli->cl_loi_list_lock);
         cli->cl_r_in_flight--;
-        list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
-                
+        cfs_list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
                 if (cli->cl_r_in_flight >= cli->cl_max_rpcs_in_flight) {
                         /* No free request slots anymore */
                         break;
                 }
 
-                mcw = list_entry(l, struct mdc_cache_waiter, mcw_entry);
-                list_del_init(&mcw->mcw_entry);
+                mcw = cfs_list_entry(l, struct mdc_cache_waiter, mcw_entry);
+                cfs_list_del_init(&mcw->mcw_entry);
                 cli->cl_r_in_flight++;
                 cfs_waitq_signal(&mcw->mcw_waitq);
         }
         /* Empty waiting list? Decrease reqs in-flight number */
-        
-        spin_unlock(&cli->cl_loi_list_lock);
+
+        client_obd_list_unlock(&cli->cl_loi_list_lock);
 }