Whamcloud - gitweb
Land b_hd_capa onto HEAD (20050809_1942)
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index 009df55..ecb0869 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/lustre_sec.h>
 #include <linux/lprocfs_status.h>
 #include <linux/lustre_acl.h>
+#include <linux/lustre_gs.h>
 #include <linux/lustre_lite.h>
 #include "mdc_internal.h"
 
@@ -138,21 +139,27 @@ int mdc_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
         lock = ldlm_handle2lock(lockh);
 
         LASSERT(lock != NULL);
-        l_lock(&lock->l_resource->lr_namespace->ns_lock);
+        lock_res_and_lock(lock);
 #ifdef __KERNEL__
         if (lock->l_ast_data && lock->l_ast_data != data) {
-                struct inode *new_inode = data;
+                struct ll_inode_info *lli = ll_i2info(data);
                 struct inode *old_inode = lock->l_ast_data;
-                LASSERTF(old_inode->i_state & I_FREEING,
-                         "Found existing inode %p/%lu/%u state %lu in lock: "
-                         "setting data to %p/%lu/%u\n", old_inode,
-                         old_inode->i_ino, old_inode->i_generation,
-                         old_inode->i_state, new_inode, new_inode->i_ino,
-                         new_inode->i_generation);
+                struct inode *new_inode = data;
+                LASSERT(lli->lli_inode_magic == LLI_INODE_MAGIC);
+                if (!(old_inode->i_state & I_FREEING)) {
+                        CERROR("Found existing inode %p/%lu/%u state %lu "
+                               "in lock: setting data to %p/%lu/%u\n",
+                               old_inode, old_inode->i_ino,
+                               old_inode->i_generation, old_inode->i_state,
+                               new_inode, new_inode->i_ino,
+                               new_inode->i_generation);
+                        unlock_res_and_lock(lock);
+                        LBUG();
+                }
         }
 #endif
         lock->l_ast_data = data;
-        l_unlock(&lock->l_resource->lr_namespace->ns_lock);
+        unlock_res_and_lock(lock);
         LDLM_LOCK_PUT(lock);
 
         EXIT;
@@ -217,7 +224,7 @@ int mdc_enqueue(struct obd_export *exp,
         int reqsize[6] = {[MDS_REQ_SECDESC_OFF] = 0,
                           [MDS_REQ_INTENT_LOCKREQ_OFF] = sizeof(*lockreq),
                           [MDS_REQ_INTENT_IT_OFF] = sizeof(*lit)};
-        int repsize[5] = {sizeof(struct ldlm_reply),
+        int repsize[8] = {sizeof(struct ldlm_reply),
                           sizeof(struct mds_body),
                           obddev->u.cli.cl_max_mds_easize};
         int req_buffers = 3, reply_buffers = 0;
@@ -233,13 +240,18 @@ int mdc_enqueue(struct obd_export *exp,
         reqsize[0] = lustre_secdesc_size();
 
         if (it->it_op & IT_OPEN) {
+                struct lustre_intent_data *lustre_data = 
+                                   (struct lustre_intent_data *) it->d.fs_data;  
                 it->it_create_mode |= S_IFREG;
                 it->it_create_mode &= ~current->fs->umask;
 
                 reqsize[req_buffers++] = sizeof(struct mds_rec_create);
                 reqsize[req_buffers++] = data->namelen + 1;
                 reqsize[req_buffers++] = obddev->u.cli.cl_max_mds_easize;
-
+                /*pack the lustre key*/
+                if (lustre_data->it_key_size > 0 && lustre_data->it_key)
+                        reqsize[req_buffers++] = lustre_data->it_key_size; 
+                
                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
                                       LDLM_ENQUEUE, req_buffers, reqsize, NULL);
                 if (!req)
@@ -256,15 +268,22 @@ int mdc_enqueue(struct obd_export *exp,
 
                 /* pack the intended request */
                 mdc_open_pack(req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF, data,
-                              it->it_create_mode, 0, it->it_flags, lmm, lmmsize);
+                              it->it_create_mode, 0, it->it_flags, lmm, lmmsize,
+                              lustre_data->it_key, lustre_data->it_key_size);
                 /* get ready for the reply */
-                repsize[3] = 4;
-                repsize[4] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
-                reply_buffers = 5;
-                req->rq_replen = lustre_msg_size(5, repsize);
+                reply_buffers = 3;
+                repsize[reply_buffers++] = sizeof(int);
+                repsize[reply_buffers++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
+                repsize[reply_buffers++] = sizeof(int);
+                repsize[reply_buffers++] = sizeof(struct crypto_key);
+                repsize[reply_buffers++] = sizeof(struct lustre_capa);
+                req->rq_replen = lustre_msg_size(reply_buffers, repsize);
         } else if (it->it_op & (IT_GETATTR | IT_LOOKUP | IT_CHDIR)) {
                 __u64 valid = data->valid | OBD_MD_FLNOTOBD | OBD_MD_FLEASIZE |
-                            OBD_MD_FLACL_ACCESS;
+                            OBD_MD_FLACL | OBD_MD_FLKEY;
+
+                /* we don't expect xattr retrieve could reach here */
+                LASSERT(!(valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST)));
 
                 reqsize[req_buffers++] = sizeof(struct mds_body);
                 reqsize[req_buffers++] = data->namelen + 1;
@@ -288,10 +307,12 @@ int mdc_enqueue(struct obd_export *exp,
                                  valid, it->it_flags, data);
                 
                 /* get ready for the reply */
-                repsize[3] = 4;
-                repsize[4] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
-                reply_buffers = 5;
-                req->rq_replen = lustre_msg_size(5, repsize);
+                reply_buffers = 3;
+                repsize[reply_buffers++] = sizeof(int);
+                repsize[reply_buffers++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
+                repsize[reply_buffers++] = sizeof(int);
+                repsize[reply_buffers++] = sizeof(struct crypto_key);
+                req->rq_replen = lustre_msg_size(reply_buffers, repsize);
         } else if (it->it_op == IT_READDIR) {
                 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
                 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
@@ -394,8 +415,9 @@ int mdc_enqueue(struct obd_export *exp,
                   LUSTRE_IT(it)->it_disposition, LUSTRE_IT(it)->it_status);
 
         /* We know what to expect, so we do any byte flipping required here */
-        LASSERT(reply_buffers == 5 || reply_buffers == 4 || 
-                reply_buffers == 3 || reply_buffers == 1);
+        LASSERT(reply_buffers == 1 || reply_buffers == 3 || 
+                reply_buffers == 5 || reply_buffers == 7 || 
+                reply_buffers == 8);
         if (reply_buffers >= 3) {
                 struct mds_body *body;
 
@@ -424,12 +446,23 @@ int mdc_enqueue(struct obd_export *exp,
                                 LASSERT(replayea);
                                 memcpy(replayea, eadata, body->eadatasize);
 
-                                LASSERT(req->rq_reqmsg->bufcount == 6);
+                                LASSERT(req->rq_reqmsg->bufcount == 6 || 
+                                        req->rq_reqmsg->bufcount == 7);
                                 req->rq_reqmsg->buflens[5] = body->eadatasize;
                                 /* If this isn't the last buffer, we might
                                  * have to shift other data around. */
                         }
                 }
+
+                /* just swab out capa to check here, and for future use */
+                if (body->valid & OBD_MD_CAPA) {
+                        struct lustre_capa *capa;
+
+                        LASSERT(it->it_op & IT_OPEN);
+                        capa = lustre_swab_repbuf(req, 7, sizeof(*capa),
+                                                  lustre_swab_lustre_capa);
+                        LASSERT(capa);
+                }
         }
 
         RETURN(rc);