Whamcloud - gitweb
Land b_hd_capa onto HEAD (20050809_1942)
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index 436a155..ecb0869 100644 (file)
 #include <linux/obd_class.h>
 #include <linux/lustre_mds.h>
 #include <linux/lustre_dlm.h>
+#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"
 
@@ -137,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;
@@ -216,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;
@@ -229,16 +237,21 @@ int mdc_enqueue(struct obd_export *exp,
 //        LDLM_DEBUG_NOLOCK("mdsintent=%s,name=%s,dir=%lu",
 //                          ldlm_it2str(it->it_op), it_name, it_inode->i_ino);
 
-        reqsize[0] = mdc_get_secdesc_size();
+        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)
@@ -255,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;
@@ -287,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,
@@ -326,7 +348,7 @@ int mdc_enqueue(struct obd_export *exp,
                 RETURN(-EINVAL);
         }
 
-        mdc_pack_secdesc(req, reqsize[0]);
+        lustre_pack_secdesc(req, reqsize[0]);
 
         mdc_get_rpc_lock(obddev->u.cli.cl_rpc_lock, it);
         rc = ldlm_cli_enqueue(exp, req, obddev->obd_namespace, res_id,
@@ -389,12 +411,13 @@ int mdc_enqueue(struct obd_export *exp,
         if (LUSTRE_IT(it)->it_status < 0 && req->rq_replay)
                 mdc_clear_replay_flag(req, LUSTRE_IT(it)->it_status);
 
-        DEBUG_REQ(D_RPCTRACE, req, "disposition: %x, status: %d",
+        DEBUG_REQ(D_DLMTRACE, req, "disposition: %x, status: %d",
                   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;
 
@@ -423,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);
@@ -526,6 +560,11 @@ int mdc_intent_lock(struct obd_export *exp, struct lustre_id *pid,
                                              &lockh);
                 }
                 if (rc) {
+                        if (ptlrpcs_check_cred(exp->exp_obd->u.cli.cl_import)) {
+                                /* return immediately if no credential held */
+                                ldlm_lock_decref(&lockh, mode);
+                                RETURN(-EACCES);
+                        }
                         memcpy(&LUSTRE_IT(it)->it_lock_handle, &lockh,
                                sizeof(lockh));
                         LUSTRE_IT(it)->it_lock_mode = mode;
@@ -602,7 +641,7 @@ int mdc_intent_lock(struct obd_export *exp, struct lustre_id *pid,
                 
                 /* we have to compare all the fields but type, because MDS can
                  * return fid/mds/ino/gen if inode lives on another MDS -bzzz */
-                if (!id_equal(cid, &mds_body->id1))
+                if (!(lookup_flags & LOOKUP_COBD) && !id_equal(cid, &mds_body->id1))
                         RETURN(-ESTALE);
         }