Whamcloud - gitweb
update lmv_placement_policy(). For directories it uses policy 'by name', for
authortappro <tappro>
Thu, 10 Aug 2006 12:14:58 +0000 (12:14 +0000)
committertappro <tappro>
Thu, 10 Aug 2006 12:14:58 +0000 (12:14 +0000)
other files - 'by parent mds'. The parent fid is added into struct
lu_placement_hint so parent mds can be taken.

lustre/include/obd.h
lustre/llite/dcache.c
lustre/llite/namei.c
lustre/lmv/lmv_obd.c

index c639f68..7d141aa 100644 (file)
@@ -579,9 +579,10 @@ struct niobuf_local {
 #define LUSTRE_OPC_CREATE    (1 << 3)
 
 struct lu_placement_hint {
-        struct qstr *ph_pname;
-        struct qstr *ph_cname;
-        int          ph_opc;
+        struct qstr   *ph_pname;
+        struct lu_fid *ph_pfid;
+        struct qstr   *ph_cname;
+        int           ph_opc;
 };
 
 #define LUSTRE_FLD_NAME  "fld"
index 5550aa9..bf59310 100644 (file)
@@ -375,6 +375,7 @@ int ll_revalidate_it(struct dentry *de, int lookup_flags,
         
         if (it->it_op & IT_CREAT) {
                 struct lu_placement_hint hint = { .ph_pname = NULL,
+                                          .ph_pfid = ll_inode2fid(parent),
                                           .ph_cname = &de->d_name,
                                           .ph_opc = LUSTRE_OPC_CREATE };
 
index 705f39e..d730418 100644 (file)
@@ -410,6 +410,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
         if (it->it_op & IT_CREAT ||
             (it->it_op & IT_OPEN && it->it_create_mode & O_CREAT)) {
                 struct lu_placement_hint hint = { .ph_pname = NULL,
+                                                  .ph_pfid = ll_inode2fid(parent),
                                                   .ph_cname = &dentry->d_name,
                                                   .ph_opc = LUSTRE_OPC_CREATE };
 
@@ -568,6 +569,7 @@ static int ll_mknod_generic(struct inode *dir, struct qstr *name, int mode,
         struct md_op_data *op_data;
         struct lu_placement_hint hint = {
                 .ph_pname = NULL,
+                .ph_pfid = ll_inode2fid(dir),
                 .ph_cname = name,
                 .ph_opc = LUSTRE_OPC_MKNOD
         };
@@ -640,6 +642,7 @@ static int ll_symlink_generic(struct inode *dir, struct dentry *dchild,
 {
         struct qstr *name = &dchild->d_name;
         struct lu_placement_hint hint = { .ph_pname = NULL,
+                                          .ph_pfid = ll_inode2fid(dir),
                                           .ph_cname = name,
                                           .ph_opc = LUSTRE_OPC_SYMLINK };
 
@@ -721,6 +724,7 @@ static int ll_mkdir_generic(struct inode *dir, struct qstr *name,
 
 {
         struct lu_placement_hint hint = { .ph_pname = NULL,
+                                          .ph_pfid = ll_inode2fid(dir),
                                           .ph_cname = name,
                                           .ph_opc = LUSTRE_OPC_MKDIR };
         struct ptlrpc_request *request = NULL;
index a832937..3b5a389 100644 (file)
@@ -646,7 +646,19 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
 static int lmv_fids_balanced(struct obd_device *obd)
 {
         ENTRY;
-        RETURN(0);
+        /* assume all is balansed for now */
+        RETURN(1);
+}
+
+static int lmv_all_chars_policy(int count, struct qstr *name)
+{
+        unsigned int c = 0;
+        unsigned int len = name->len;
+
+        while (len > 0)
+                c += name->name[-- len];
+        c = c % count;
+        return c;
 }
 
 /* returns number of target where new fid should be allocated using passed @hint
@@ -655,22 +667,35 @@ static int lmv_placement_policy(struct obd_device *obd,
                                 struct lu_placement_hint *hint)
 {
         struct lmv_obd *lmv = &obd->u.lmv;
+        int tgt;
         ENTRY;
 
         /* here are some policies to allocate new fid */
-        if (hint->ph_cname && lmv_fids_balanced(obd)) {
+        if (lmv_fids_balanced(obd)) {
                 /* allocate new fid basing on its name in the case fids are
                  * balanced, that is all sequences have more or less equal
                  * number of objects created. */
+                if (hint->ph_cname && (hint->ph_opc == LUSTRE_OPC_MKDIR))
+                        tgt = lmv_all_chars_policy(lmv->desc.ld_tgt_count,
+                                                   hint->ph_cname);
+                else {
+                        /* default policy is to use parent MDS */
+                        LASSERT(fid_is_sane(hint->ph_pfid));
+                        tgt = lmv_fld_lookup(obd, hint->ph_pfid);
+                }
         } else {
                 /* sequences among all tgts are not well balanced, allocate new
                  * fid taking this into account to balance them. */
+                tgt = -EINVAL;
         }
-        //stub to place new dir on second MDS
-        if (hint->ph_opc == LUSTRE_OPC_MKDIR)
-                RETURN(lmv->desc.ld_tgt_count - 1);
 
-        RETURN(0);
+        /* if cannot get proper MDS, use master one */
+        if (tgt < 0) {
+                CERROR("Cannot choose MDS, err = %i\n", tgt);
+                tgt = 0;
+        }
+
+        RETURN(tgt);
 }
 
 static int lmv_fid_init(struct obd_export *exp)