int ofd_object_ff_check(const struct lu_env *env, struct ofd_object *fo) { int rc = 0; ENTRY; if (!fo->ofo_ff_exists) { /* * This actually means that we don't know whether the object * has the "fid" EA or not. */ rc = dt_xattr_get(env, ofd_object_child(fo), &LU_BUF_NULL, XATTR_NAME_FID, BYPASS_CAPA); if (rc >= 0 || rc == -ENODATA) { /* * Here we assume that, if the object doesn't have the * "fid" EA, the caller will add one, unless a fatal * error (e.g., a memory or disk failure) prevents it * from doing so. */ fo->ofo_ff_exists = 1; } if (rc > 0) rc = 0; } RETURN(rc); }
/** * \retval +ve: the lfsck_namespace is broken, the caller should reset it. * \retval 0: succeed. * \retval -ve: failed cases. */ static int lfsck_namespace_load(const struct lu_env *env, struct lfsck_component *com) { int len = com->lc_file_size; int rc; rc = dt_xattr_get(env, com->lc_obj, lfsck_buf_get(env, com->lc_file_disk, len), XATTR_NAME_LFSCK_NAMESPACE, BYPASS_CAPA); if (rc == len) { struct lfsck_namespace *ns = com->lc_file_ram; lfsck_namespace_le_to_cpu(ns, (struct lfsck_namespace *)com->lc_file_disk); if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) { CWARN("%s: invalid lfsck_namespace magic %#x != %#x\n", lfsck_lfsck2name(com->lc_lfsck), ns->ln_magic, LFSCK_NAMESPACE_MAGIC); rc = 1; } else { rc = 0; } } else if (rc != -ENODATA) { CERROR("%s: fail to load lfsck_namespace: expected = %d, " "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), len, rc); if (rc >= 0) rc = 1; } return rc; }
static int lfsck_update_lma(const struct lu_env *env, struct lfsck_instance *lfsck, struct dt_object *obj) { struct lfsck_thread_info *info = lfsck_env_info(env); struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram; struct dt_device *dt = lfsck->li_bottom; struct lustre_mdt_attrs *lma = &info->lti_lma; struct lu_buf *buf; struct thandle *th; int fl; int rc; ENTRY; if (bk->lb_param & LPF_DRYRUN) RETURN(0); buf = lfsck_buf_get(env, info->lti_lma_old, LMA_OLD_SIZE); rc = dt_xattr_get(env, obj, buf, XATTR_NAME_LMA, BYPASS_CAPA); if (rc < 0) { if (rc != -ENODATA) RETURN(rc); fl = LU_XATTR_CREATE; lustre_lma_init(lma, lfsck_dto2fid(obj), LMAC_FID_ON_OST, 0); } else { if (rc != LMA_OLD_SIZE && rc != sizeof(struct lustre_mdt_attrs)) RETURN(-EINVAL); fl = LU_XATTR_REPLACE; lustre_lma_swab(lma); lustre_lma_init(lma, lfsck_dto2fid(obj), lma->lma_compat | LMAC_FID_ON_OST, lma->lma_incompat); } lustre_lma_swab(lma); th = dt_trans_create(env, dt); if (IS_ERR(th)) RETURN(PTR_ERR(th)); buf = lfsck_buf_get(env, lma, sizeof(*lma)); rc = dt_declare_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th); if (rc != 0) GOTO(stop, rc); rc = dt_trans_start(env, dt, th); if (rc != 0) GOTO(stop, rc); rc = dt_xattr_set(env, obj, buf, XATTR_NAME_LMA, fl, th, BYPASS_CAPA); GOTO(stop, rc); stop: dt_trans_stop(env, dt, th); return rc; }
static int out_xattr_get(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct object_update *update = tti->tti_u.update.tti_update; struct lu_buf *lbuf = &tti->tti_buf; struct object_update_reply *reply = tti->tti_u.update.tti_update_reply; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; struct object_update_result *update_result; int idx = tti->tti_u.update.tti_update_reply_index; int rc; ENTRY; if (!lu_object_exists(&obj->do_lu)) { set_bit(LU_OBJECT_HEARD_BANSHEE, &obj->do_lu.lo_header->loh_flags); RETURN(-ENOENT); } name = object_update_param_get(update, 0, NULL); if (IS_ERR(name)) { CERROR("%s: empty name for xattr get: rc = %ld\n", tgt_name(tsi->tsi_tgt), PTR_ERR(name)); RETURN(PTR_ERR(name)); } update_result = object_update_result_get(reply, 0, NULL); if (update_result == NULL) { CERROR("%s: empty name for xattr get: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(-EPROTO); } lbuf->lb_len = (int)tti->tti_u.update.tti_update->ou_result_size; lbuf->lb_buf = update_result->our_data; if (lbuf->lb_len == 0) lbuf->lb_buf = 0; dt_read_lock(env, obj, MOR_TGT_CHILD); rc = dt_xattr_get(env, obj, lbuf, name); dt_read_unlock(env, obj); if (rc < 0) lbuf->lb_len = 0; CDEBUG(D_INFO, "%s: "DFID" get xattr %s len %d\n", tgt_name(tsi->tsi_tgt), PFID(lu_object_fid(&obj->do_lu)), name, (int)lbuf->lb_len); GOTO(out, rc); out: object_update_result_insert(reply, lbuf->lb_buf, lbuf->lb_len, idx, rc); RETURN(0); }
static int lfsck_links_read(const struct lu_env *env, struct dt_object *obj, struct linkea_data *ldata) { int rc; ldata->ld_buf = lu_buf_check_and_alloc(&lfsck_env_info(env)->lti_linkea_buf, PAGE_CACHE_SIZE); if (ldata->ld_buf->lb_buf == NULL) return -ENOMEM; if (!dt_object_exists(obj)) return -ENODATA; rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA); if (rc == -ERANGE) { /* Buf was too small, figure out what we need. */ lu_buf_free(ldata->ld_buf); rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA); if (rc < 0) return rc; ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc); if (ldata->ld_buf->lb_buf == NULL) return -ENOMEM; rc = dt_xattr_get(env, obj, ldata->ld_buf, XATTR_NAME_LINK, BYPASS_CAPA); } if (rc < 0) return rc; linkea_init(ldata); return 0; }
static int out_xattr_get(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct update *update = tti->tti_u.update.tti_update; struct lu_buf *lbuf = &tti->tti_buf; struct update_reply *reply = tti->tti_u.update.tti_update_reply; struct dt_object *obj = tti->tti_u.update.tti_dt_object; char *name; void *ptr; int rc; ENTRY; name = (char *)update_param_buf(update, 0, NULL); if (name == NULL) { CERROR("%s: empty name for xattr get: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } ptr = update_get_buf_internal(reply, 0, NULL); LASSERT(ptr != NULL); /* The first 4 bytes(int) are used to store the result */ lbuf->lb_buf = (char *)ptr + sizeof(int); lbuf->lb_len = UPDATE_BUFFER_SIZE - sizeof(struct update_reply); dt_read_lock(env, obj, MOR_TGT_CHILD); rc = dt_xattr_get(env, obj, lbuf, name, NULL); dt_read_unlock(env, obj); if (rc < 0) { lbuf->lb_len = 0; GOTO(out, rc); } if (rc == 0) { lbuf->lb_len = 0; GOTO(out, rc = -ENOENT); } lbuf->lb_len = rc; rc = 0; CDEBUG(D_INFO, "%s: "DFID" get xattr %s len %d\n", tgt_name(tsi->tsi_tgt), PFID(lu_object_fid(&obj->do_lu)), name, (int)lbuf->lb_len); out: *(int *)ptr = rc; reply->ur_lens[0] = lbuf->lb_len + sizeof(int); RETURN(rc); }