* GPL HEADER END
*/
/*
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
* Use is subject to license terms.
*
* Author: Johann Lombardi <johann@whamcloud.com>
/**
* Helper function to retrieve DMU object id from fid for accounting object
*/
-uint64_t osd_quota_fid2dmu(const struct lu_fid *fid)
+dnode_t *osd_quota_fid2dmu(const struct osd_device *osd,
+ const struct lu_fid *fid)
{
LASSERT(fid_is_acct(fid));
if (fid_oid(fid) == ACCT_GROUP_OID)
- return DMU_GROUPUSED_OBJECT;
- return DMU_USERUSED_OBJECT;
+ return osd->od_groupused_dn;
+ return osd->od_userused_dn;
}
/**
static uint64_t osd_objset_user_iused(struct osd_device *osd, uint64_t uidbytes)
{
uint64_t refdbytes, availbytes, usedobjs, availobjs;
- uint64_t uidobjs;
+ uint64_t uidobjs, bshift;
/* get fresh statfs info */
dmu_objset_space(osd->od_os, &refdbytes, &availbytes,
&usedobjs, &availobjs);
/* estimate the number of objects based on the disk usage */
+ bshift = fls64(osd->od_max_blksz) - 1;
uidobjs = osd_objs_count_estimate(refdbytes, usedobjs,
- uidbytes >> SPA_MAXBLOCKSHIFT);
+ uidbytes >> bshift, bshift);
if (uidbytes > 0)
/* if we have at least 1 byte, we have at least one dnode ... */
uidobjs = max_t(uint64_t, uidobjs, 1);
* \param dtrec - is the record to fill with space usage information
* \param dtkey - is the id the of the user or group for which we would
* like to access disk usage.
- * \param capa - is the capability, not used.
*
* \retval +ve - success : exact match
* \retval -ve - failure
static int osd_acct_index_lookup(const struct lu_env *env,
struct dt_object *dtobj,
struct dt_rec *dtrec,
- const struct dt_key *dtkey,
- struct lustre_capa *capa)
+ const struct dt_key *dtkey)
{
struct osd_thread_info *info = osd_oti_get(env);
char *buf = info->oti_buf;
+ size_t buflen = sizeof(info->oti_buf);
struct lquota_acct_rec *rec = (struct lquota_acct_rec *)dtrec;
struct osd_object *obj = osd_dt_obj(dtobj);
struct osd_device *osd = osd_obj2dev(obj);
int rc;
- uint64_t oid;
+ dnode_t *dn;
ENTRY;
rec->bspace = rec->ispace = 0;
/* convert the 64-bit uid/gid into a string */
- sprintf(buf, "%llx", *((__u64 *)dtkey));
- /* fetch DMU object ID (DMU_USERUSED_OBJECT/DMU_GROUPUSED_OBJECT) to be
+ snprintf(buf, buflen, "%llx", *((__u64 *)dtkey));
+ /* fetch DMU object (DMU_USERUSED_OBJECT/DMU_GROUPUSED_OBJECT) to be
* used */
- oid = osd_quota_fid2dmu(lu_object_fid(&dtobj->do_lu));
+ dn = osd_quota_fid2dmu(osd, lu_object_fid(&dtobj->do_lu));
/* disk usage (in bytes) is maintained by DMU.
* DMU_USERUSED_OBJECT/DMU_GROUPUSED_OBJECT are special objects which
- * not associated with any dmu_but_t (see dnode_special_open()).
- * As a consequence, we cannot use udmu_zap_lookup() here since it
- * requires a valid oo_db. */
- rc = -zap_lookup(osd->od_os, oid, buf, sizeof(uint64_t), 1,
- &rec->bspace);
- if (rc == -ENOENT)
+ * not associated with any dmu_but_t (see dnode_special_open()). */
+ rc = osd_zap_lookup(osd, dn->dn_object, dn, buf, sizeof(uint64_t), 1,
+ &rec->bspace);
+ if (rc == -ENOENT) {
/* user/group has not created anything yet */
CDEBUG(D_QUOTA, "%s: id %s not found in DMU accounting ZAP\n",
osd->od_svname, buf);
- else if (rc)
+ } else if (rc) {
RETURN(rc);
+ }
- if (osd->od_quota_iused_est) {
+ if (!osd_dmu_userobj_accounting_available(osd)) {
if (rec->bspace != 0)
/* estimate #inodes in use */
rec->ispace = osd_objset_user_iused(osd, rec->bspace);
- RETURN(+1);
+ rc = 1;
+ } else {
+ snprintf(buf, buflen, OSD_DMU_USEROBJ_PREFIX "%llx",
+ *((__u64 *)dtkey));
+ rc = osd_zap_lookup(osd, dn->dn_object, dn, buf,
+ sizeof(uint64_t), 1, &rec->ispace);
+ if (rc == -ENOENT) {
+ CDEBUG(D_QUOTA,
+ "%s: id %s not found dnode accounting\n",
+ osd->od_svname, buf);
+ } else if (rc == 0) {
+ rc = 1;
+ }
}
- /* as for inode accounting, it is not maintained by DMU, so we just
- * use our own ZAP to track inode usage */
- rc = -zap_lookup(osd->od_os, obj->oo_db->db_object,
- buf, sizeof(uint64_t), 1, &rec->ispace);
- if (rc == -ENOENT)
- /* user/group has not created any file yet */
- CDEBUG(D_QUOTA, "%s: id %s not found in accounting ZAP\n",
- osd->od_svname, buf);
- else if (rc)
- RETURN(rc);
-
- RETURN(+1);
+ RETURN(rc);
}
/**
*
* \param dt - osd index object
* \param attr - not used
- * \param capa - BYPASS_CAPA
*/
static struct dt_it *osd_it_acct_init(const struct lu_env *env,
struct dt_object *dt,
- __u32 attr,
- struct lustre_capa *capa)
+ __u32 attr)
{
struct osd_thread_info *info = osd_oti_get(env);
struct osd_it_quota *it;
struct lu_object *lo = &dt->do_lu;
struct osd_device *osd = osd_dev(lo->lo_dev);
- int rc;
+ dnode_t *dn;
+ int rc;
ENTRY;
LASSERT(lu_object_exists(lo));
if (info == NULL)
RETURN(ERR_PTR(-ENOMEM));
- it = &info->oti_it_quota;
+ OBD_ALLOC_PTR(it);
+ if (it == NULL)
+ RETURN(ERR_PTR(-ENOMEM));
+
memset(it, 0, sizeof(*it));
- it->oiq_oid = osd_quota_fid2dmu(lu_object_fid(lo));
+ dn = osd_quota_fid2dmu(osd, lu_object_fid(lo));
+ it->oiq_oid = dn->dn_object;
/* initialize zap cursor */
rc = osd_zap_cursor_init(&it->oiq_zc, osd->od_os, it->oiq_oid, 0);
- if (rc)
+ if (rc != 0) {
+ OBD_FREE_PTR(it);
RETURN(ERR_PTR(rc));
+ }
/* take object reference */
lu_object_get(lo);
*/
static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
{
- struct osd_it_quota *it = (struct osd_it_quota *)di;
+ struct osd_it_quota *it = (struct osd_it_quota *)di;
ENTRY;
+
osd_zap_cursor_fini(it->oiq_zc);
- lu_object_put(env, &it->oiq_obj->oo_dt.do_lu);
+ osd_object_put(env, it->oiq_obj);
+ OBD_FREE_PTR(it);
+
EXIT;
}
* to read bytes we need to call zap_lookup explicitly.
*/
static int osd_zap_cursor_retrieve_value(const struct lu_env *env,
- zap_cursor_t *zc, char *buf,
- int buf_size, int *bytes_read)
+ struct osd_it_quota *it,
+ char *buf, int buf_size,
+ int *bytes_read)
{
+ const struct lu_fid *fid = lu_object_fid(&it->oiq_obj->oo_dt.do_lu);
zap_attribute_t *za = &osd_oti_get(env)->oti_za;
+ zap_cursor_t *zc = it->oiq_zc;
+ struct osd_device *osd = osd_obj2dev(it->oiq_obj);
int rc, actual_size;
rc = -zap_cursor_retrieve(zc, za);
if (unlikely(rc != 0))
- return -rc;
+ return rc;
if (unlikely(za->za_integer_length <= 0))
return -ERANGE;
buf_size = za->za_num_integers;
}
- rc = -zap_lookup(zc->zc_objset, zc->zc_zapobj,
- za->za_name, za->za_integer_length,
- buf_size, buf);
-
+ /* use correct special ID to request bytes used */
+ rc = osd_zap_lookup(osd, fid_oid(fid) == ACCT_GROUP_OID ?
+ DMU_GROUPUSED_OBJECT : DMU_USERUSED_OBJECT, NULL,
+ za->za_name, za->za_integer_length, buf_size, buf);
if (likely(rc == 0))
*bytes_read = actual_size;
rec->ispace = rec->bspace = 0;
/* retrieve block usage from the DMU accounting object */
- rc = osd_zap_cursor_retrieve_value(env, it->oiq_zc,
- (char *)&rec->bspace,
+ rc = osd_zap_cursor_retrieve_value(env, it, (char *)&rec->bspace,
sizeof(uint64_t), &bytes_read);
if (rc)
RETURN(rc);
- if (osd->od_quota_iused_est) {
+ if (!osd_dmu_userobj_accounting_available(osd)) {
if (rec->bspace != 0)
/* estimate #inodes in use */
rec->ispace = osd_objset_user_iused(osd, rec->bspace);
/* inode accounting is not maintained by DMU, so we use our own ZAP to
* track inode usage */
- rc = -zap_lookup(osd->od_os, it->oiq_obj->oo_db->db_object,
- za->za_name, sizeof(uint64_t), 1, &rec->ispace);
+ rc = osd_zap_lookup(osd, it->oiq_obj->oo_dn->dn_object,
+ it->oiq_obj->oo_dn, za->za_name, sizeof(uint64_t),
+ 1, &rec->ispace);
if (rc == -ENOENT)
/* user/group has not created any file yet */
CDEBUG(D_QUOTA, "%s: id %s not found in accounting ZAP\n",