X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fosd-zfs%2Fosd_object.c;h=ad6752fb8ef1bd3d7069e9b749f9b524ebafde17;hb=f6995cf04407dff15d6ca79ca44cfa97dc6eb014;hp=bc28b55ed16e7e3813ff3433ca8e4325866fba80;hpb=9dacbee7fe35e7dac5637c8ad5c62ece41d3c8ed;p=fs%2Flustre-release.git diff --git a/lustre/osd-zfs/osd_object.c b/lustre/osd-zfs/osd_object.c index bc28b55..ad6752f 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -26,10 +26,8 @@ /* * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. - */ -/* - * Copyright (c) 2012, 2013, Intel Corporation. - * Use is subject to license terms. + * + * Copyright (c) 2012, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -354,7 +352,7 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj) buf.lb_buf = lma; buf.lb_len = sizeof(info->oti_buf); - rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA, BYPASS_CAPA); + rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA); if (rc > 0) { rc = 0; lustre_lma_swab(lma); @@ -736,8 +734,7 @@ static int osd_object_write_locked(const struct lu_env *env, static int osd_attr_get(const struct lu_env *env, struct dt_object *dt, - struct lu_attr *attr, - struct lustre_capa *capa) + struct lu_attr *attr) { struct osd_object *obj = osd_dt_obj(dt); uint64_t blocks; @@ -907,8 +904,7 @@ static int osd_declare_attr_set(const struct lu_env *env, * to a transaction group. */ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt, - const struct lu_attr *la, struct thandle *handle, - struct lustre_capa *capa) + const struct lu_attr *la, struct thandle *handle) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); @@ -1052,7 +1048,6 @@ static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah, { LASSERT(ah); - memset(ah, 0, sizeof(*ah)); ah->dah_parent = parent; ah->dah_mode = child_mode; } @@ -1207,19 +1202,28 @@ out: * dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT) called and then assigned * to a transaction group. */ -int __osd_object_create(const struct lu_env *env, struct osd_device *osd, +int __osd_object_create(const struct lu_env *env, struct osd_object *obj, dmu_buf_t **dbp, dmu_tx_t *tx, struct lu_attr *la, uint64_t parent) { - uint64_t oid; - int rc; + uint64_t oid; + int rc; + struct osd_device *osd = osd_obj2dev(obj); + const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu); + dmu_object_type_t type = DMU_OT_PLAIN_FILE_CONTENTS; /* Assert that the transaction has been assigned to a transaction group. */ LASSERT(tx->tx_txg != 0); + /* Use DMU_OTN_UINT8_METADATA for local objects so their data blocks + * would get an additional ditto copy */ + if (unlikely(S_ISREG(la->la_mode) && + fid_seq_is_local_file(fid_seq(fid)))) + type = DMU_OTN_UINT8_METADATA; + /* Create a new DMU object. */ - oid = dmu_object_alloc(osd->od_os, DMU_OT_PLAIN_FILE_CONTENTS, 0, + oid = dmu_object_alloc(osd->od_os, type, 0, DMU_OT_SA, DN_MAX_BONUSLEN, tx); rc = -sa_buf_hold(osd->od_os, oid, osd_obj_tag, dbp); LASSERTF(rc == 0, "sa_buf_hold "LPU64" failed: %d\n", oid, rc); @@ -1277,7 +1281,7 @@ int __osd_zap_create(const struct lu_env *env, struct osd_device *osd, return __osd_attr_init(env, osd, oid, tx, la, parent); } -static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_device *osd, +static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh) { @@ -1289,14 +1293,14 @@ static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_device *osd, * We set ZAP_FLAG_UINT64_KEY to let ZFS know than we are going to use * binary keys */ LASSERT(S_ISREG(la->la_mode)); - rc = __osd_zap_create(env, osd, &db, oh->ot_tx, la, parent, + rc = __osd_zap_create(env, osd_obj2dev(obj), &db, oh->ot_tx, la, parent, ZAP_FLAG_UINT64_KEY); if (rc) return ERR_PTR(rc); return db; } -static dmu_buf_t *osd_mkdir(const struct lu_env *env, struct osd_device *osd, +static dmu_buf_t *osd_mkdir(const struct lu_env *env, struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh) { @@ -1304,21 +1308,23 @@ static dmu_buf_t *osd_mkdir(const struct lu_env *env, struct osd_device *osd, int rc; LASSERT(S_ISDIR(la->la_mode)); - rc = __osd_zap_create(env, osd, &db, oh->ot_tx, la, parent, 0); + rc = __osd_zap_create(env, osd_obj2dev(obj), &db, + oh->ot_tx, la, parent, 0); if (rc) return ERR_PTR(rc); return db; } -static dmu_buf_t* osd_mkreg(const struct lu_env *env, struct osd_device *osd, +static dmu_buf_t *osd_mkreg(const struct lu_env *env, struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh) { - dmu_buf_t *db; - int rc; + dmu_buf_t *db; + int rc; + struct osd_device *osd = osd_obj2dev(obj); LASSERT(S_ISREG(la->la_mode)); - rc = __osd_object_create(env, osd, &db, oh->ot_tx, la, parent); + rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent); if (rc) return ERR_PTR(rc); @@ -1340,7 +1346,7 @@ static dmu_buf_t* osd_mkreg(const struct lu_env *env, struct osd_device *osd, return db; } -static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_device *osd, +static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh) { @@ -1348,13 +1354,13 @@ static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_device *osd, int rc; LASSERT(S_ISLNK(la->la_mode)); - rc = __osd_object_create(env, osd, &db, oh->ot_tx, la, parent); + rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent); if (rc) return ERR_PTR(rc); return db; } -static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_device *osd, +static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh) { @@ -1365,14 +1371,14 @@ static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_device *osd, if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) la->la_valid |= LA_RDEV; - rc = __osd_object_create(env, osd, &db, oh->ot_tx, la, parent); + rc = __osd_object_create(env, obj, &db, oh->ot_tx, la, parent); if (rc) return ERR_PTR(rc); return db; } typedef dmu_buf_t *(*osd_obj_type_f)(const struct lu_env *env, - struct osd_device *osd, + struct osd_object *obj, struct lu_attr *la, uint64_t parent, struct osd_thandle *oh); @@ -1421,7 +1427,7 @@ static inline int osd_init_lma(const struct lu_env *env, struct osd_object *obj, buf.lb_len = sizeof(*lma); rc = osd_xattr_set_internal(env, obj, &buf, XATTR_NAME_LMA, - LU_XATTR_CREATE, oh, BYPASS_CAPA); + LU_XATTR_CREATE, oh); return rc; } @@ -1471,7 +1477,7 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt, if (hint && hint->dah_parent) zapid = osd_dt_obj(hint->dah_parent)->oo_db->db_object; - db = osd_create_type_f(dof->dof_type)(env, osd, attr, zapid, oh); + db = osd_create_type_f(dof->dof_type)(env, obj, attr, zapid, oh); if (IS_ERR(db)) GOTO(out, rc = PTR_ERR(db)); @@ -1592,145 +1598,6 @@ static int osd_object_ref_del(const struct lu_env *env, return rc; } -static int capa_is_sane(const struct lu_env *env, struct osd_device *dev, - struct lustre_capa *capa, struct lustre_capa_key *keys) -{ - struct osd_thread_info *oti = osd_oti_get(env); - struct obd_capa *oc; - int i, rc = 0; - ENTRY; - - oc = capa_lookup(dev->od_capa_hash, capa, 0); - if (oc) { - if (capa_is_expired(oc)) { - DEBUG_CAPA(D_ERROR, capa, "expired"); - rc = -ESTALE; - } - capa_put(oc); - RETURN(rc); - } - - spin_lock(&capa_lock); - for (i = 0; i < 2; i++) { - if (keys[i].lk_keyid == capa->lc_keyid) { - oti->oti_capa_key = keys[i]; - break; - } - } - spin_unlock(&capa_lock); - - if (i == 2) { - DEBUG_CAPA(D_ERROR, capa, "no matched capa key"); - RETURN(-ESTALE); - } - - rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key); - if (rc) - RETURN(rc); - if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) - { - DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch"); - RETURN(-EACCES); - } - - oc = capa_add(dev->od_capa_hash, capa); - capa_put(oc); - - RETURN(0); -} - -static int osd_object_auth(const struct lu_env *env, struct dt_object *dt, - struct lustre_capa *capa, __u64 opc) -{ - const struct lu_fid *fid = lu_object_fid(&dt->do_lu); - struct osd_device *dev = osd_dev(dt->do_lu.lo_dev); - int rc; - - if (!dev->od_fl_capa) - return 0; - - if (capa == BYPASS_CAPA) - return 0; - - if (!capa) { - CERROR("no capability is provided for fid "DFID"\n", PFID(fid)); - return -EACCES; - } - - if (!lu_fid_eq(fid, &capa->lc_fid)) { - DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",PFID(fid)); - return -EACCES; - } - - if (!capa_opc_supported(capa, opc)) { - DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc); - return -EACCES; - } - - if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) { - DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc); - return -EACCES; - } - - return 0; -} - -static struct obd_capa *osd_capa_get(const struct lu_env *env, - struct dt_object *dt, - struct lustre_capa *old, - __u64 opc) -{ - struct osd_thread_info *info = osd_oti_get(env); - const struct lu_fid *fid = lu_object_fid(&dt->do_lu); - struct osd_object *obj = osd_dt_obj(dt); - struct osd_device *dev = osd_obj2dev(obj); - struct lustre_capa_key *key = &info->oti_capa_key; - struct lustre_capa *capa = &info->oti_capa; - struct obd_capa *oc; - int rc; - ENTRY; - - if (!dev->od_fl_capa) - RETURN(ERR_PTR(-ENOENT)); - - LASSERT(dt_object_exists(dt)); - LASSERT(osd_invariant(obj)); - - /* renewal sanity check */ - if (old && osd_object_auth(env, dt, old, opc)) - RETURN(ERR_PTR(-EACCES)); - - capa->lc_fid = *fid; - capa->lc_opc = opc; - capa->lc_uid = 0; - capa->lc_flags = dev->od_capa_alg << 24; - capa->lc_timeout = dev->od_capa_timeout; - capa->lc_expiry = 0; - - oc = capa_lookup(dev->od_capa_hash, capa, 1); - if (oc) { - LASSERT(!capa_is_expired(oc)); - RETURN(oc); - } - - spin_lock(&capa_lock); - *key = dev->od_capa_keys[1]; - spin_unlock(&capa_lock); - - capa->lc_keyid = key->lk_keyid; - capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout; - - rc = capa_hmac(capa->lc_hmac, capa, key->lk_key); - if (rc) { - DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc); - LBUG(); - RETURN(ERR_PTR(rc)); - } - - oc = capa_add(dev->od_capa_hash, capa); - RETURN(oc); -} - static int osd_object_sync(const struct lu_env *env, struct dt_object *dt, __u64 start, __u64 end) { @@ -1771,7 +1638,6 @@ static struct dt_object_operations osd_obj_ops = { .do_declare_xattr_del = osd_declare_xattr_del, .do_xattr_del = osd_xattr_del, .do_xattr_list = osd_xattr_list, - .do_capa_get = osd_capa_get, .do_object_sync = osd_object_sync, }; @@ -1786,8 +1652,7 @@ static struct lu_object_operations osd_lu_obj_ops = { static int osd_otable_it_attr_get(const struct lu_env *env, struct dt_object *dt, - struct lu_attr *attr, - struct lustre_capa *capa) + struct lu_attr *attr) { attr->la_valid = 0; return 0;