Whamcloud - gitweb
b=20298
[fs/lustre-release.git] / lustre / osd / osd_handler.c
index 7235a3c..0f7713b 100644 (file)
 #include <linux/fs.h>
 /* XATTR_{REPLACE,CREATE} */
 #include <linux/xattr.h>
-/*
- * XXX temporary stuff: direct access to ldiskfs/jdb. Interface between osd
- * and file system is not yet specified.
- */
-/* handle_t, journal_start(), journal_stop() */
-#include <linux/jbd.h>
-/* LDISKFS_SB() */
-#include <linux/ldiskfs_fs.h>
-#include <linux/ldiskfs_jbd.h>
 /* simple_mkdir() */
 #include <lvfs.h>
 
@@ -77,7 +68,6 @@
 
 /* fid_is_local() */
 #include <lustre_fid.h>
-#include <linux/lustre_iam.h>
 
 #include "osd_internal.h"
 #include "osd_igif.h"
@@ -311,9 +301,16 @@ static struct inode *osd_iget(struct osd_thread_info *info,
                               struct osd_device *dev,
                               const struct osd_inode_id *id)
 {
-        struct inode *inode;
+        struct inode *inode = NULL;
 
+#ifdef HAVE_EXT4_LDISKFS
+        inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
+        if (IS_ERR(inode))
+        /* Newer kernels return an error instead of a NULL pointer */
+                inode = NULL;
+#else
         inode = iget(osd_sb(dev), id->oii_ino);
+#endif
         if (inode == NULL) {
                 CERROR("no inode\n");
                 inode = ERR_PTR(-EACCES);
@@ -575,7 +572,7 @@ static struct thandle *osd_trans_start(const struct lu_env *env,
                          * be used.
                          */
 
-                        jh = journal_start(osd_journal(dev), p->tp_credits);
+                        jh = ldiskfs_journal_start_sb(osd_sb(dev), p->tp_credits);
                         if (!IS_ERR(jh)) {
                                 oh->ot_handle = jh;
                                 th = &oh->ot_super;
@@ -589,8 +586,8 @@ static struct thandle *osd_trans_start(const struct lu_env *env,
                                 /* add commit callback */
                                 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
                                 lu_context_enter(&th->th_ctx);
-                                journal_callback_set(jh, osd_trans_commit_cb,
-                                                     (struct journal_callback *)&oh->ot_jcb);
+                                osd_journal_callback_set(jh, osd_trans_commit_cb,
+                                                         (struct journal_callback *)&oh->ot_jcb);
                                         LASSERT(oti->oti_txns == 0);
                                         LASSERT(oti->oti_r_locks == 0);
                                         LASSERT(oti->oti_w_locks == 0);
@@ -632,7 +629,7 @@ static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
                 if (result != 0)
                         CERROR("Failure in transaction hook: %d\n", result);
                 oh->ot_handle = NULL;
-                result = journal_stop(hdl);
+                result = ldiskfs_journal_stop(hdl);
                 if (result != 0)
                         CERROR("Failure to stop transaction: %d\n", result);
         }
@@ -910,8 +907,8 @@ static const int osd_dto_credits_noquota[DTO_NR] = {
         /**
          * Xattr set. The same as xattr of EXT3.
          * DATA_TRANS_BLOCKS(14)
-         * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS are
-         *           also counted in. Do not know why?
+         * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
+         * are also counted in. Do not know why?
          */
         [DTO_XATTR_SET]     = 14,
         [DTO_LOG_REC]       = 14,
@@ -925,9 +922,9 @@ static const int osd_dto_credits_noquota[DTO_NR] = {
         [DTO_WRITE_BLOCK]   = 14,
         /**
          * Attr set credits for chown.
-         * 3 (inode bit, group, GDT)
+         * This is extra credits for setattr, and it is null without quota
          */
-        [DTO_ATTR_SET_CHOWN]= 3
+        [DTO_ATTR_SET_CHOWN]= 0
 };
 
 /**
@@ -990,11 +987,11 @@ static const int osd_dto_credits_quota[DTO_NR] = {
         [DTO_WRITE_BLOCK]   = 16,
         /**
          * Attr set credits for chown.
-         * 3 (inode bit, group, GDT) +
+         * It is added to already set setattr credits
          * 2 * QUOTA_INIT_BLOCKS(25) +
          * 2 * QUOTA_DEL_BLOCKS(9)
          */
-        [DTO_ATTR_SET_CHOWN]= 71
+        [DTO_ATTR_SET_CHOWN]= 68,
 };
 
 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
@@ -1361,25 +1358,6 @@ static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
         return 0;
 }
 
-extern struct inode *ldiskfs_create_inode(handle_t *handle,
-                                          struct inode * dir, int mode);
-extern int ldiskfs_add_entry(handle_t *handle, struct dentry *dentry,
-                             struct inode *inode);
-extern int ldiskfs_delete_entry(handle_t *handle,
-                                struct inode * dir,
-                                struct ldiskfs_dir_entry_2 * de_del,
-                                struct buffer_head * bh);
-extern struct buffer_head * ldiskfs_find_entry(struct dentry *dentry,
-                                               struct ldiskfs_dir_entry_2
-                                               ** res_dir);
-extern int ldiskfs_add_dot_dotdot(handle_t *handle, struct inode *dir,
-                                  struct inode *inode);
-
-extern int ldiskfs_xattr_set_handle(handle_t *handle, struct inode *inode,
-                                    int name_index, const char *name,
-                                    const void *value, size_t value_len,
-                                    int flags);
-
 static struct dentry * osd_child_dentry_get(const struct lu_env *env,
                                             struct osd_object *obj,
                                             const char *name,
@@ -1446,13 +1424,6 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
         return result;
 }
 
-
-extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
-                           int recsize, handle_t *handle);
-
-extern int iam_lfix_create(struct inode *obj, int keysize, int ptrsize,
-                           int recsize, handle_t *handle);
-
 enum {
         OSD_NAME_LEN = 255
 };
@@ -1480,7 +1451,7 @@ static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
                  */
 
                 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
-                                         sizeof (struct lu_fid_pack),
+                                         sizeof (struct osd_fid_pack),
                                          oth->ot_handle);
         }
         return result;
@@ -1759,10 +1730,29 @@ static inline void osd_igif_get(const struct lu_env *env, struct inode  *inode,
 /**
  * Helper function to pack the fid
  */
-static inline void osd_fid_pack(const struct lu_env *env, const struct lu_fid *fid,
-                                struct dt_rec *pack)
+void osd_fid_pack(struct osd_fid_pack *pack, const struct dt_rec *fid,
+                  struct lu_fid *befider)
 {
-        fid_pack((struct lu_fid_pack *)pack, fid, &osd_oti_get(env)->oti_fid);
+        fid_cpu_to_be(befider, (struct lu_fid *)fid);
+        memcpy(pack->fp_area, befider, sizeof(*befider));
+        pack->fp_len =  sizeof(*befider) + 1;
+}
+
+int osd_fid_unpack(struct lu_fid *fid, const struct osd_fid_pack *pack)
+{
+        int result;
+
+        result = 0;
+        switch (pack->fp_len) {
+        case sizeof *fid + 1:
+                memcpy(fid, pack->fp_area, sizeof *fid);
+                fid_be_to_cpu(fid, fid);
+                break;
+        default:
+                CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
+                result = -EIO;
+        }
+        return result;
 }
 
 /**
@@ -2167,7 +2157,6 @@ static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
                            const struct dt_index_features *feat)
 {
         struct iam_descr *descr;
-        struct dt_object *dt = &o->oo_dt;
 
         if (osd_object_is_root(o))
                 return feat == &dt_directory_features;
@@ -2176,21 +2165,10 @@ static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
 
         descr = o->oo_dir->od_container.ic_descr;
         if (feat == &dt_directory_features) {
-                if (descr->id_rec_size == sizeof(struct lu_fid_pack))
+                if (descr->id_rec_size == sizeof(struct osd_fid_pack))
                         return 1;
-
-                if (descr == &iam_htree_compat_param) {
-                        /* if it is a HTREE dir then there is good chance that,
-                         * we dealing with ext3 directory here with no FIDs. */
-
-                        if (descr->id_rec_size ==
-                            sizeof ((struct ldiskfs_dir_entry_2 *)NULL)->inode) {
-
-                                dt->do_index_ops = &osd_index_ea_ops;
-                                return 1;
-                        }
-                }
-                return 0;
+                else
+                        return 0;
         } else {
                 return
                         feat->dif_keysize_min <= descr->id_key_size &&
@@ -2546,6 +2524,7 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
         struct iam_container  *bag = &obj->oo_dir->od_container;
         struct osd_thread_info *oti = osd_oti_get(env);
         struct iam_iterator    *it = &oti->oti_idx_it;
+        struct iam_rec *iam_rec;
         int rc;
         ENTRY;
 
@@ -2564,9 +2543,17 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
         iam_it_init(it, bag, 0, ipd);
 
         rc = iam_it_get(it, (struct iam_key *)key);
-        if (rc >= 0)
-                iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)rec);
+        if (rc >= 0) {
+                if (S_ISDIR(obj->oo_inode->i_mode))
+                        iam_rec = (struct iam_rec *)oti->oti_fid_packed;
+                else
+                        iam_rec = (struct iam_rec *) rec;
 
+                iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
+                if (S_ISDIR(obj->oo_inode->i_mode))
+                        osd_fid_unpack((struct lu_fid *) rec,
+                                       (struct osd_fid_pack *)iam_rec);
+        }
         iam_it_put(it);
         iam_it_fini(it);
         osd_ipd_put(env, bag, ipd);
@@ -2599,6 +2586,8 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
 #ifdef HAVE_QUOTA_SUPPORT
         cfs_cap_t              save = current->cap_effective;
 #endif
+        struct osd_thread_info *oti = osd_oti_get(env);
+        struct iam_rec *iam_rec = (struct iam_rec *)oti->oti_fid_packed;
         int rc;
 
         ENTRY;
@@ -2624,8 +2613,12 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
         else
                 current->cap_effective &= ~CFS_CAP_SYS_RESOURCE_MASK;
 #endif
+        if (S_ISDIR(obj->oo_inode->i_mode))
+                osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
+        else
+                iam_rec = (struct iam_rec *) rec;
         rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
-                        (struct iam_rec *)rec, ipd);
+                        iam_rec, ipd);
 #ifdef HAVE_QUOTA_SUPPORT
         current->cap_effective = save;
 #endif
@@ -2746,11 +2739,10 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
                              struct dt_rec *rec, const struct dt_key *key)
 {
         struct inode               *dir    = obj->oo_inode;
-        struct osd_thread_info     *info   = osd_oti_get(env);
         struct dentry              *dentry;
         struct ldiskfs_dir_entry_2 *de;
         struct buffer_head         *bh;
-        struct lu_fid              *fid = &info->oti_fid;
+        struct lu_fid              *fid = (struct lu_fid *) rec;
         int ino;
         int rc;
 
@@ -2765,8 +2757,6 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
                 ino = le32_to_cpu(de->inode);
                 brelse(bh);
                 rc = osd_ea_fid_get(env, obj, ino, fid);
-                if (rc == 0)
-                        osd_fid_pack(env, fid, rec);
         } else
                 rc = -ENOENT;
 
@@ -2847,8 +2837,7 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
                                struct lustre_capa *capa, int ignore_quota)
 {
         struct osd_object        *obj   = osd_dt_obj(dt);
-        struct lu_fid            *fid   = &osd_oti_get(env)->oti_fid;
-        const struct lu_fid_pack *pack  = (const struct lu_fid_pack *)rec;
+        struct lu_fid            *fid   = (struct lu_fid *) rec;
         const char               *name  = (const char *)key;
         struct osd_object        *child;
 #ifdef HAVE_QUOTA_SUPPORT
@@ -2865,9 +2854,6 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
                 RETURN(-EACCES);
 
-        rc = fid_unpack(pack, fid);
-        if (rc != 0)
-                RETURN(rc);
         child = osd_object_find(env, dt, fid);
         if (!IS_ERR(child)) {
                 struct inode *inode = obj->oo_inode;
@@ -3080,7 +3066,7 @@ static int osd_it_iam_rec(const struct lu_env *env,
         struct osd_it_iam *it        = (struct osd_it_iam *)di;
         struct osd_thread_info *info = osd_oti_get(env);
         struct lu_fid     *fid       = &info->oti_fid;
-        const struct lu_fid_pack *rec;
+        const struct osd_fid_pack *rec;
         char *name;
         int namelen;
         __u64 hash;
@@ -3092,11 +3078,11 @@ static int osd_it_iam_rec(const struct lu_env *env,
 
         namelen = iam_it_key_size(&it->oi_it);
 
-        rec = (const struct lu_fid_pack *) iam_it_rec_get(&it->oi_it);
+        rec = (const struct osd_fid_pack *) iam_it_rec_get(&it->oi_it);
         if (IS_ERR(rec))
                 RETURN(PTR_ERR(rec));
 
-        rc = fid_unpack(rec, fid);
+        rc = osd_fid_unpack(fid, rec);
         if (rc)
                 RETURN(rc);
 
@@ -3189,7 +3175,7 @@ static struct dt_it *osd_it_ea_init(const struct lu_env *env,
         it->oie_file.f_op         = obj->oo_inode->i_fop;
         it->oie_file.private_data = NULL;
         lu_object_get(lo);
-        RETURN((struct dt_it*) it);
+        RETURN((struct dt_it *) it);
 }
 
 /**
@@ -3599,7 +3585,6 @@ static int osd_mount(const struct lu_env *env,
         struct lustre_sb_info    *lsi;
 
         ENTRY;
-
         if (o->od_mount != NULL) {
                 CERROR("Already mounted (%s)\n", dev);
                 RETURN(-EEXIST);
@@ -3719,16 +3704,9 @@ static int osd_process_config(const struct lu_env *env,
         RETURN(err);
 }
 
-extern void ldiskfs_orphan_cleanup (struct super_block * sb,
-                                    struct ldiskfs_super_block * es);
-
 static int osd_recovery_complete(const struct lu_env *env,
                                  struct lu_device *d)
 {
-        struct osd_device *o = osd_dev(d);
-        ENTRY;
-        /* TODO: orphans handling */
-        ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
         RETURN(0);
 }