Whamcloud - gitweb
LU-8424 osd-zfs: ZFS macro DN_MAX_BONUSLEN is deprecated
[fs/lustre-release.git] / lustre / osd-zfs / osd_oi.c
index d17ae6f..230d103 100644 (file)
@@ -90,6 +90,7 @@ static const struct named_oid oids[] = {
        { .oid = OFD_HEALTH_CHECK_OID, .name = HEALTH_CHECK },
        { .oid = ACCT_USER_OID,        .name = "acct_usr_inode" },
        { .oid = ACCT_GROUP_OID,       .name = "acct_grp_inode" },
+       { .oid = ACCT_PROJECT_OID,     .name = "acct_prj_inode" },
        { .oid = REPLY_DATA_OID,       .name = REPLY_DATA },
        { .oid = 0 }
 };
@@ -148,6 +149,9 @@ osd_oi_create(const struct lu_env *env, struct osd_device *o,
        if (rc == 0)
                return -EEXIST;
 
+       if (o->od_dt_dev.dd_rdonly)
+               return -EROFS;
+
        /* create fid-to-dnode index */
        tx = dmu_tx_create(o->od_os);
        if (tx == NULL)
@@ -156,7 +160,6 @@ osd_oi_create(const struct lu_env *env, struct osd_device *o,
        dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, 1, NULL);
        dmu_tx_hold_bonus(tx, parent);
        dmu_tx_hold_zap(tx, parent, TRUE, name);
-       LASSERT(tx->tx_objset->os_sa);
        dmu_tx_hold_sa_create(tx, ZFS_SA_BASE_ATTR_SIZE);
 
        rc = -dmu_tx_assign(tx, TXG_WAIT);
@@ -165,11 +168,11 @@ osd_oi_create(const struct lu_env *env, struct osd_device *o,
                return rc;
        }
 
-       oid = zap_create_flags(o->od_os, 0, ZAP_FLAG_HASH64,
-                              DMU_OT_DIRECTORY_CONTENTS,
-                              14, /* == ZFS fzap_default_block_shift */
-                              DN_MAX_INDBLKSHIFT, /* indirect block shift */
-                              DMU_OT_SA, DN_MAX_BONUSLEN, tx);
+       oid = osd_zap_create_flags(o->od_os, 0, ZAP_FLAG_HASH64,
+                                  DMU_OT_DIRECTORY_CONTENTS,
+                                  14, /* == ZFS fzap_default_block_shift */
+                                  DN_MAX_INDBLKSHIFT,
+                                  0, tx);
 
        rc = -sa_handle_get(o->od_os, oid, NULL, SA_HDL_PRIVATE, &sa_hdl);
        if (rc)
@@ -261,6 +264,14 @@ int fid_is_on_ost(const struct lu_env *env, struct osd_device *osd,
 
        rc = osd_fld_lookup(env, osd, fid_seq(fid), range);
        if (rc != 0) {
+               /* During upgrade, OST FLDB might not be loaded because
+                * OST FLDB is not created until 2.6, so if some DNE
+                * filesystem upgrade from 2.5 to 2.7/2.8, they will
+                * not be able to find the sequence from local FLDB
+                * cache see fld_index_init(). */
+               if (rc == -ENOENT && osd->od_is_ost)
+                       RETURN(1);
+
                if (rc != -ENOENT)
                        CERROR("%s: "DFID" lookup failed: rc = %d\n",
                               osd_name(osd), PFID(fid), rc);
@@ -471,6 +482,26 @@ static inline int fid_is_fs_root(const struct lu_fid *fid)
                fid_oid(fid) == OSD_FS_ROOT_OID;
 }
 
+static inline int osd_oid(struct osd_device *dev, __u32 local_oid,
+                              uint64_t *oid)
+{
+       switch (local_oid) {
+       case ACCT_USER_OID:
+               *oid = dev->od_iusr_oid;
+               return 0;
+       case ACCT_GROUP_OID:
+               *oid = dev->od_igrp_oid;
+               return 0;
+       case ACCT_PROJECT_OID:
+               /* TODO: real oid */
+               CERROR("unsupported quota oid: %#x\n", local_oid);
+               return -ENOTSUPP;
+       }
+
+       LASSERTF(0, "invalid oid: %u for quota type", local_oid);
+       return -ENOTSUPP;
+}
+
 int osd_fid_lookup(const struct lu_env *env, struct osd_device *dev,
                   const struct lu_fid *fid, uint64_t *oid)
 {
@@ -484,10 +515,9 @@ int osd_fid_lookup(const struct lu_env *env, struct osd_device *dev,
                RETURN(-ENOENT);
 
        if (unlikely(fid_is_acct(fid))) {
-               if (fid_oid(fid) == ACCT_USER_OID)
-                       *oid = dev->od_iusr_oid;
-               else
-                       *oid = dev->od_igrp_oid;
+               rc = osd_oid(dev, fid_oid(fid), oid);
+               if (rc)
+                       RETURN(rc);
        } else if (unlikely(fid_is_fs_root(fid))) {
                *oid = dev->od_root;
        } else {
@@ -519,8 +549,8 @@ osd_oi_remove_table(const struct lu_env *env, struct osd_device *o, int key)
 
        oi = o->od_oi_table[key];
        if (oi) {
-               if (oi->oi_db)
-                       sa_buf_rele(oi->oi_db, osd_obj_tag);
+               if (oi->oi_dn)
+                       osd_dnode_rele(oi->oi_dn);
                OBD_FREE_PTR(oi);
                o->od_oi_table[key] = NULL;
        }
@@ -550,7 +580,7 @@ osd_oi_add_table(const struct lu_env *env, struct osd_device *o,
        }
 
        o->od_oi_table[key] = oi;
-       __osd_obj2dbuf(env, o->od_os, oi->oi_zapid, &oi->oi_db);
+       __osd_obj2dnode(env, o->od_os, oi->oi_zapid, &oi->oi_dn);
 
        return 0;
 }
@@ -886,9 +916,9 @@ int osd_idc_find_and_init(const struct lu_env *env, struct osd_device *osd,
 
        idc = osd_idc_find(env, osd, fid);
        if (idc != NULL) {
-               if (obj->oo_db == NULL)
+               if (obj->oo_dn == NULL)
                        return 0;
-               idc->oic_dnode = obj->oo_db->db_object;
+               idc->oic_dnode = obj->oo_dn->dn_object;
                return 0;
        }
 
@@ -897,8 +927,8 @@ int osd_idc_find_and_init(const struct lu_env *env, struct osd_device *osd,
        if (IS_ERR(idc))
                return PTR_ERR(idc);
 
-       if (obj->oo_db)
-               idc->oic_dnode = obj->oo_db->db_object;
+       if (obj->oo_dn)
+               idc->oic_dnode = obj->oo_dn->dn_object;
 
        return 0;
 }