* Use is subject to license terms.
*/
/*
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
* Use is subject to license terms.
*/
/*
* Author: Johann Lombardi <johann@whamcloud.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
#define DEBUG_SUBSYSTEM S_OSD
#include <lustre_ver.h>
#include <libcfs/libcfs.h>
-#include <lustre_fsfilt.h>
#include <obd_support.h>
#include <lustre_net.h>
#include <obd.h>
extern struct dt_body_operations osd_body_ops;
static struct dt_object_operations osd_obj_otable_it_ops;
-extern cfs_mem_cache_t *osd_object_kmem;
+extern struct kmem_cache *osd_object_kmem;
static void
osd_object_sa_fini(struct osd_object *obj)
la->la_uid = osa->uid;
la->la_gid = osa->gid;
la->la_nlink = osa->nlink;
- la->la_flags = osa->flags;
+ la->la_flags = attrs_zfs2fs(osa->flags);
la->la_size = osa->size;
if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
{
struct osd_object *mo;
- OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, CFS_ALLOC_IO);
+ OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, __GFP_IO);
if (mo != NULL) {
struct lu_object *l;
*/
obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
- cfs_mb();
+ smp_mb();
obj->oo_dt.do_lu.lo_header->loh_attr |= LOHA_EXISTS;
RETURN(0);
}
+static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
+{
+ struct osd_thread_info *info = osd_oti_get(env);
+ struct lu_buf buf;
+ int rc;
+ struct lustre_mdt_attrs *lma;
+ ENTRY;
+
+ CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
+ lma = (struct lustre_mdt_attrs *)info->oti_buf;
+ 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);
+ if (rc > 0) {
+ rc = 0;
+ lustre_lma_swab(lma);
+ if (unlikely((lma->lma_incompat & ~LMA_INCOMPAT_SUPP) ||
+ CFS_FAIL_CHECK(OBD_FAIL_OSD_LMA_INCOMPAT))) {
+ CWARN("%s: unsupported incompat LMA feature(s) %#x for "
+ "fid = "DFID"\n", osd_obj2dev(obj)->od_svname,
+ lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
+ PFID(lu_object_fid(&obj->oo_dt.do_lu)));
+ rc = -EOPNOTSUPP;
+ }
+ } else if (rc == -ENODATA) {
+ /* haven't initialize LMA xattr */
+ rc = 0;
+ }
+
+ RETURN(rc);
+}
+
/*
* Concurrency: no concurrent access is possible that early in object
* life-cycle.
LASSERT(osd_invariant(obj));
+ if (fid_is_otable_it(&l->lo_header->loh_fid)) {
+ obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
+ l->lo_header->loh_attr |= LOHA_EXISTS;
+ RETURN(0);
+ }
+
rc = osd_fid_lookup(env, osd, lu_object_fid(l), &oid);
if (rc == 0) {
LASSERT(obj->oo_db == NULL);
rc = __osd_obj2dbuf(env, osd->od_objset.os, oid,
&obj->oo_db, osd_obj_tag);
- if (rc == 0) {
- LASSERT(obj->oo_db);
- rc = osd_object_init0(env, obj);
- } else {
+ if (rc != 0) {
CERROR("%s: lookup "DFID"/"LPX64" failed: rc = %d\n",
osd->od_svname, PFID(lu_object_fid(l)), oid, rc);
+ GOTO(out, rc);
}
+ LASSERT(obj->oo_db);
+ rc = osd_object_init0(env, obj);
+ if (rc != 0)
+ GOTO(out, rc);
+
+ rc = osd_check_lma(env, obj);
+ if (rc != 0)
+ GOTO(out, rc);
} else if (rc == -ENOENT) {
- if (fid_is_otable_it(&l->lo_header->loh_fid)) {
- obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
- /* LFSCK iterator object is special without inode */
- l->lo_header->loh_attr |= LOHA_EXISTS;
- }
rc = 0;
}
LASSERT(osd_invariant(obj));
+out:
RETURN(rc);
}
oh = container_of0(handle, struct osd_thandle, ot_super);
LASSERT(obj->oo_sa_hdl != NULL);
+ LASSERT(oh->ot_tx != NULL);
dmu_tx_hold_sa(oh->ot_tx, obj->oo_sa_hdl, 0);
+ if (oh->ot_tx->tx_err != 0)
+ RETURN(-oh->ot_tx->tx_err);
sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
bspace = toqb(bspace * blksize);
&osa->rdev, 8);
}
if (la->la_valid & LA_FLAGS) {
- osa->flags = obj->oo_attr.la_flags = la->la_flags;
+ osa->flags = attrs_fs2zfs(la->la_flags);
+ /* many flags are not supported by zfs, so ensure a good cached
+ * copy */
+ obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(uos), NULL,
&osa->flags, 8);
}
static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
struct dt_object *parent, struct dt_object *child,
- cfs_umode_t child_mode)
+ umode_t child_mode)
{
LASSERT(ah);
memset(ah, 0, sizeof(*ah));
+ ah->dah_parent = parent;
ah->dah_mode = child_mode;
}
RETURN(rc);
}
-int __osd_attr_init(const struct lu_env *env, udmu_objset_t *uos,
- uint64_t oid, dmu_tx_t *tx, struct lu_attr *la)
+int __osd_attr_init(const struct lu_env *env, udmu_objset_t *uos, uint64_t oid,
+ dmu_tx_t *tx, struct lu_attr *la, uint64_t parent)
{
sa_bulk_attr_t *bulk;
sa_handle_t *sa_hdl;
struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
uint64_t gen;
- uint64_t parent;
uint64_t crtime[2];
timestruc_t now;
int cnt;
gen = dmu_tx_get_txg(tx);
ZFS_TIME_ENCODE(&now, crtime);
- /* XXX: this should be real id of parent for ZPL access, but we have no
- * such info in OSD, probably it can be part of dt_object_format */
- parent = 0;
osa->atime[0] = la->la_atime;
osa->ctime[0] = la->la_ctime;
osa->gid = la->la_gid;
osa->rdev = la->la_rdev;
osa->nlink = la->la_nlink;
- osa->flags = la->la_flags;
+ osa->flags = attrs_fs2zfs(la->la_flags);
osa->size = la->la_size;
/* Now add in all of the "SA" attributes */
* to a transaction group.
*/
int __osd_object_create(const struct lu_env *env, udmu_objset_t *uos,
- dmu_buf_t **dbp, dmu_tx_t *tx,
- struct lu_attr *la, void *tag)
+ dmu_buf_t **dbp, dmu_tx_t *tx, struct lu_attr *la,
+ uint64_t parent, void *tag)
{
uint64_t oid;
int rc;
la->la_size = 0;
la->la_nlink = 1;
- return __osd_attr_init(env, uos, oid, tx, la);
+ return __osd_attr_init(env, uos, oid, tx, la, parent);
}
/*
* a conversion from the different internal ZAP hash formats being used. */
int __osd_zap_create(const struct lu_env *env, udmu_objset_t *uos,
dmu_buf_t **zap_dbp, dmu_tx_t *tx,
- struct lu_attr *la, void *tag, zap_flags_t flags)
+ struct lu_attr *la, uint64_t parent,
+ void *tag, zap_flags_t flags)
{
uint64_t oid;
int rc;
la->la_size = 2;
la->la_nlink = 1;
- return __osd_attr_init(env, uos, oid, tx, la);
+ return __osd_attr_init(env, uos, oid, tx, la, parent);
}
static dmu_buf_t *osd_mkidx(const struct lu_env *env, struct osd_device *osd,
- struct lu_attr *la, struct osd_thandle *oh)
+ struct lu_attr *la, uint64_t parent,
+ struct osd_thandle *oh)
{
dmu_buf_t *db;
int rc;
* binary keys */
LASSERT(S_ISREG(la->la_mode));
rc = __osd_zap_create(env, &osd->od_objset, &db, oh->ot_tx, la,
- osd_obj_tag, ZAP_FLAG_UINT64_KEY);
+ parent, osd_obj_tag, 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,
- struct lu_attr *la, struct osd_thandle *oh)
+ struct lu_attr *la, uint64_t parent,
+ struct osd_thandle *oh)
{
dmu_buf_t *db;
int rc;
LASSERT(S_ISDIR(la->la_mode));
rc = __osd_zap_create(env, &osd->od_objset, &db, oh->ot_tx, la,
- osd_obj_tag, 0);
+ parent, osd_obj_tag, 0);
if (rc)
return ERR_PTR(rc);
return db;
}
static dmu_buf_t* osd_mkreg(const struct lu_env *env, struct osd_device *osd,
- struct lu_attr *la, struct osd_thandle *oh)
+ struct lu_attr *la, uint64_t parent,
+ struct osd_thandle *oh)
{
dmu_buf_t *db;
int rc;
LASSERT(S_ISREG(la->la_mode));
rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
- osd_obj_tag);
+ parent, osd_obj_tag);
if (rc)
return ERR_PTR(rc);
}
static dmu_buf_t *osd_mksym(const struct lu_env *env, struct osd_device *osd,
- struct lu_attr *la, struct osd_thandle *oh)
+ struct lu_attr *la, uint64_t parent,
+ struct osd_thandle *oh)
{
dmu_buf_t *db;
int rc;
LASSERT(S_ISLNK(la->la_mode));
rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
- osd_obj_tag);
+ parent, osd_obj_tag);
if (rc)
return ERR_PTR(rc);
return db;
}
static dmu_buf_t *osd_mknod(const struct lu_env *env, struct osd_device *osd,
- struct lu_attr *la, struct osd_thandle *oh)
+ struct lu_attr *la, uint64_t parent,
+ struct osd_thandle *oh)
{
dmu_buf_t *db;
int rc;
la->la_valid |= LA_RDEV;
rc = __osd_object_create(env, &osd->od_objset, &db, oh->ot_tx, la,
- osd_obj_tag);
+ parent, osd_obj_tag);
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 lu_attr *la, struct osd_thandle *oh);
+typedef dmu_buf_t *(*osd_obj_type_f)(const struct lu_env *env,
+ struct osd_device *osd,
+ struct lu_attr *la,
+ uint64_t parent,
+ struct osd_thandle *oh);
static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
{
struct lu_buf buf;
int rc;
- lustre_lma_init(lma, fid);
+ lustre_lma_init(lma, fid, 0, 0);
lustre_lma_swab(lma);
buf.lb_buf = lma;
buf.lb_len = sizeof(*lma);
LASSERT(obj->oo_db == NULL);
- db = osd_create_type_f(dof->dof_type)(env, osd, attr, oh);
+ /* to follow ZFS on-disk format we need
+ * to initialize parent dnode properly */
+ zapid = 0;
+ 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);
if (IS_ERR(db))
- GOTO(out, rc = PTR_ERR(th));
+ GOTO(out, rc = PTR_ERR(db));
zde->zde_pad = 0;
zde->zde_dnode = db->db_object;