Whamcloud - gitweb
add an assert, from alex.
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index f033377..d0ca61d 100644 (file)
@@ -153,6 +153,9 @@ static int lustre_connect_mds(struct super_block *sb, char *lmv,
         obd_set_info(md_obd->obd_self_export, strlen("async"), "async",
                      sizeof(async), &async);
 
+        if (mds_security == NULL)
+                mds_security = "null";
+        
         err = obd_set_info(md_obd->obd_self_export, strlen("sec"), "sec",
                            strlen(mds_security), mds_security);
         
@@ -230,6 +233,7 @@ out_disconnect:
 out:
         RETURN(err);
 }
+
 static int lustre_connect_ost(struct super_block *sb, char *lov, 
                               struct obd_connect_data *data, 
                               char *oss_security, int async, int pag)
@@ -259,15 +263,23 @@ static int lustre_connect_ost(struct super_block *sb, char *lov,
                 RETURN(err);
         }
 
-        if (pag) {
+        /* FIXME Because of the async nature of file i/o, we never know
+         * who is actually dirty the pages; and any process have chance
+         * to trigger dirty-flushing within its own process context. So
+         * for simplicity we simply use root's credential, we suppose root
+         * always have credential.
+         */
+        if (pag)
                 sec_flags = PTLRPC_SEC_FL_PAG;
-                err = obd_set_info(obd->obd_self_export,
-                                   strlen("sec_flags"), "sec_flags",
-                                   sizeof(sec_flags), &sec_flags);
-                if (err) {
-                        OBD_FREE(data, sizeof(*data));
-                        RETURN(err);
-                }
+        else
+                sec_flags = PTLRPC_SEC_FL_OSS;
+
+        err = obd_set_info(obd->obd_self_export,
+                           strlen("sec_flags"), "sec_flags",
+                           sizeof(sec_flags), &sec_flags);
+        if (err) {
+                OBD_FREE(data, sizeof(*data));
+                RETURN(err);
         }
 
         err = obd_connect(&dt_conn, obd, &sbi->ll_sb_uuid, data, 0);
@@ -578,6 +590,9 @@ void ll_lli_init(struct ll_inode_info *lli)
         lli->lli_open_fd_exec_count = 0;
         lli->lli_audit_mask = AUDIT_OFF;
         lli->lli_key_info = NULL;
+        init_waitqueue_head(&lli->lli_dirty_wait);
+        lli->lli_io_epoch = 0;
+        INIT_LIST_HEAD(&lli->lli_capas);
 }
 
 int ll_fill_super(struct super_block *sb, void *data, int silent)
@@ -731,7 +746,7 @@ static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
         if (rc)
                 GOTO(out_cleanup, rc);
 
-        rc = obd_connect(&md_conn, obd, &lmv_uuid, NULL, 0);
+        rc = obd_connect(&md_conn, obd, &lmv_uuid, NULL, OBD_OPT_REAL_CLIENT);
         if (rc) {
                 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, rc);
                 GOTO(out_cleanup, rc);
@@ -830,10 +845,9 @@ static int lustre_process_profile(struct super_block *sb,
                                   char **lov, char **lmv, char **gkc)  
 {
         struct ll_sb_info *sbi = ll_s2sbi(sb);
-        struct lustre_profile *lprof;
         struct config_llog_instance cfg;
+        struct lustre_profile *lprof;
         int len, err = 0;
-        
         ENTRY;
 
         if (!lmd->lmd_profile)
@@ -851,8 +865,8 @@ static int lustre_process_profile(struct super_block *sb,
                 GOTO(out, err = -ENOMEM);
         memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
 
-        /* generate a string unique to this super, let's try
-         the address of the super itself.*/
+        /* generate a string unique to this super, let's try the address of the
+         * super itself. */
         len = (sizeof(sb) * 2) + 1;
         OBD_ALLOC(sbi->ll_instance, len);
         if (sbi->ll_instance == NULL)
@@ -876,19 +890,36 @@ static int lustre_process_profile(struct super_block *sb,
 
         OBD_ALLOC(*lov, strlen(lprof->lp_lov) +
                   strlen(sbi->ll_instance) + 2);
+        if (*lov == NULL)
+                GOTO(out, err = -ENOMEM);
+        
         sprintf(*lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
 
         OBD_ALLOC(*lmv, strlen(lprof->lp_lmv) +
                   strlen(sbi->ll_instance) + 2);
+        if (*lmv == NULL)
+                GOTO(out_free_lov, err = -ENOMEM);
+
         sprintf(*lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
 
         if (lprof->lp_gkc) {
                OBD_ALLOC(*gkc, strlen(lprof->lp_gkc) +
-                               strlen(sbi->ll_instance) + 2);
+                         strlen(sbi->ll_instance) + 2);
+               if (*gkc == NULL)
+                       GOTO(out_free_lmv, err = -ENOMEM);
+               
                sprintf(*gkc, "%s-%s", lprof->lp_gkc, sbi->ll_instance); 
         }
+        
+        RETURN(err);
+out_free_lmv:
+        OBD_FREE(*lmv, strlen(lprof->lp_lmv) +
+                 strlen(sbi->ll_instance) + 2);
+out_free_lov:
+        OBD_FREE(*lov, strlen(lprof->lp_lov) +
+                 strlen(sbi->ll_instance) + 2);
 out: 
-        RETURN(err)
+        return err
 }
 
 static int lustre_clean_profile(struct ll_sb_info *sbi, int force_umount)
@@ -915,6 +946,12 @@ static int lustre_clean_profile(struct ll_sb_info *sbi, int force_umount)
                 cfg.cfg_uuid = sbi->ll_sb_uuid;
 
                 OBD_ALLOC(cl_prof, len);
+                if (!cl_prof) {
+                        CERROR("can't allocate memory, "
+                               "skipping processing cleanup profile.\n");
+                        GOTO(free_lmd, err = -ENOMEM);
+                }
+                
                 sprintf(cl_prof, "%s-clean", lmd->lmd_profile);
                 err = lustre_process_log(lmd, cl_prof, &cfg, 0);
                 if (err < 0) {
@@ -923,11 +960,12 @@ static int lustre_clean_profile(struct ll_sb_info *sbi, int force_umount)
                 }
                 OBD_FREE(cl_prof, len);
         }
+        EXIT;
 free_lmd:
         if (sbi->ll_instance)
                 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
         OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
-        RETURN(err);
+        return err;
 }
 
 int lustre_fill_super(struct super_block *sb, void *data, int silent)
@@ -966,7 +1004,8 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
 
         if (err)
                 GOTO(out_free, err);
-        
+
+        EXIT;
 out_dev:
         if (lmv)
                 OBD_FREE(lmv, strlen(lmv) + 1);
@@ -975,11 +1014,11 @@ out_dev:
         if (gkc)
                 OBD_FREE(gkc, strlen(gkc) + 1);
         
-        RETURN(err);
+        return err;
 out_free:
         lustre_clean_profile(sbi, 0);
         lustre_free_sbi(sb);
-        GOTO(out_dev, err);
+        goto out_dev;
 
 } /* lustre_fill_super */
 
@@ -1020,16 +1059,6 @@ int ll_process_config_update(struct ll_sb_info *sbi, int clean)
                 RETURN(0);
         }
 
-        rc = obd_cancel_unused(sbi->ll_md_exp, NULL,
-                               LDLM_FL_CONFIG_CHANGE, NULL);
-        if (rc != 0)
-                CWARN("obd_cancel_unused(mdc): %d\n", rc);
-
-        rc = obd_cancel_unused(sbi->ll_dt_exp, NULL,
-                               LDLM_FL_CONFIG_CHANGE, NULL);
-        if (rc != 0)
-                CWARN("obd_cancel_unused(lov): %d\n", rc);
-
         cfg.cfg_instance = sbi->ll_instance;
         cfg.cfg_uuid = sbi->ll_sb_uuid;
         cfg.cfg_local_nid = lmd->lmd_local_nid;
@@ -1125,11 +1154,13 @@ void ll_clear_inode(struct inode *inode)
         struct lustre_id id;
         struct ll_inode_info *lli = ll_i2info(inode);
         struct ll_sb_info *sbi = ll_i2sbi(inode);
+        struct obd_capa *ocapa, *tmp;
         ENTRY;
 
         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
                inode->i_generation, inode);
 
+        LASSERT(ll_is_inode_dirty(inode) == 0);
         ll_inode2id(&id, inode);
         
         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
@@ -1177,10 +1208,10 @@ void ll_clear_inode(struct inode *inode)
                 lli->lli_remote_acl = NULL;
         }
 
-        if (lli->lli_trunc_capa) {
-                OBD_FREE(lli->lli_trunc_capa, sizeof(struct lustre_capa));
-                lli->lli_trunc_capa = NULL;
-        }
+        list_for_each_entry_safe(ocapa, tmp, &lli->lli_capas, u.client.lli_list)
+                capa_put(ocapa);
+
+        LASSERT(!mapping_has_pages(inode->i_mapping));
 
         lli->lli_inode_magic = LLI_INODE_DEAD;
         EXIT;
@@ -1206,7 +1237,6 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
         struct ll_sb_info *sbi = ll_i2sbi(inode);
         struct ptlrpc_request *request = NULL;
         struct mdc_op_data *op_data;
-        struct lustre_capa *trunc_capa = NULL;
         int ia_valid = attr->ia_valid;
         int err, rc = 0;
         ENTRY;
@@ -1260,11 +1290,17 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
                 OBD_ALLOC(op_data, sizeof(*op_data));
                 if (op_data == NULL)
                         RETURN(-ENOMEM);
-                ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
+                ll_inode2mdc_data(op_data, inode, (OBD_MD_FLID | OBD_MD_MEA));
 
-                if (ia_valid & (ATTR_UID | ATTR_GID)) {
+                if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE)) {
                         rc = ll_crypto_get_mac(inode, attr, NULL, 0, &key, 
                                                &key_size);
+                        if (rc) {
+                                CERROR("can not get right mac, rc=%d\n", rc);
+                                if (key && key_size)
+                                        OBD_FREE(key, key_size);
+                                RETURN(rc);
+                        }
                 }
                 rc = md_setattr(sbi->ll_md_exp, op_data,
                                 attr, key, key_size, NULL, 0, NULL, 
@@ -1287,21 +1323,11 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
                 }
 
                 if (attr->ia_valid & ATTR_SIZE) {
-                        /* XXX: hack for truncate capa */
-                        rc = mdc_req2lustre_capa(request, 0, &trunc_capa);
+                        rc = ll_set_trunc_capa(request, 0, inode);
                         if (rc) {
                                 ptlrpc_req_finished(request);
                                 RETURN(rc);
                         }
-
-                        spin_lock(&lli->lli_lock);
-                        if (trunc_capa) {
-                                if (lli->lli_trunc_capa)
-                                        OBD_FREE(lli->lli_trunc_capa,
-                                                 sizeof(*trunc_capa));
-                                lli->lli_trunc_capa = trunc_capa;
-                        }
-                        spin_unlock(&lli->lli_lock);
                 }
 
                 /* We call inode_setattr to adjust timestamps, but we first
@@ -1423,7 +1449,7 @@ int ll_setattr_raw(struct inode *inode, struct iattr *attr)
 
                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
                                 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
-                rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
+                rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL, NULL);
                 obdo_free(oa);
                 if (rc)
                         CERROR("obd_setattr fails: rc = %d\n", rc);
@@ -2252,7 +2278,7 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                         obdo_free(oa);
                         RETURN(-ENOMEM);
                 }
-                ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
+                ll_inode2mdc_data(op_data, inode, (OBD_MD_FLID | OBD_MD_MEA));
 
                 memset(&attr, 0x0, sizeof(attr));
                 attr.ia_attr_flags = flags;
@@ -2277,7 +2303,7 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP 
                               | OBD_MD_FLIFID;
 
-                rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
+                rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL, NULL);
                 obdo_free(oa);
                 if (rc) {
                         if (rc != -EPERM && rc != -EACCES)