X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fquota%2Flquota_disk.c;h=8d31852824e59aebd6bc25f7d7c0059d1423bccb;hb=8931d9070415e808e09bb4befd7cd38ef2431149;hp=777b2ab68afac26411a70db2d9268b84c5875569;hpb=294aa9cb666c48e02da1057c222fe5f206ce38fc;p=fs%2Flustre-release.git diff --git a/lustre/quota/lquota_disk.c b/lustre/quota/lquota_disk.c index 777b2ab..8d31852 100644 --- a/lustre/quota/lquota_disk.c +++ b/lustre/quota/lquota_disk.c @@ -21,7 +21,7 @@ * GPL HEADER END */ /* - * Copyright (c) 2012 Intel, Inc. + * Copyright (c) 2012, 2013, Intel Corporation. * Use is subject to license terms. * * Author: Johann Lombardi @@ -48,10 +48,6 @@ * - lquota_disk_update_ver: update version of an index file */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif - #define DEBUG_SUBSYSTEM S_LQUOTA #include "lquota_internal.h" @@ -100,7 +96,7 @@ out: /* * helper function to generate the filename associated with a slave index file */ -static inline int lquota_disk_slv_filename(struct lu_fid *glb_fid, +static inline int lquota_disk_slv_filename(const struct lu_fid *glb_fid, struct obd_uuid *uuid, char *filename) { @@ -184,7 +180,7 @@ struct dt_object *lquota_disk_dir_find_create(const struct lu_env *env, GOTO(out, rc); parent = dt_locate_at(env, dev, &qti->qti_fid, - dev->dd_lu_dev.ld_site->ls_top_dev); + dev->dd_lu_dev.ld_site->ls_top_dev, NULL); if (IS_ERR(parent)) GOTO(out, rc = PTR_ERR(parent)); } else { @@ -320,7 +316,7 @@ struct dt_object *lquota_disk_glb_find_create(const struct lu_env *env, struct dt_object *lquota_disk_slv_find(const struct lu_env *env, struct dt_device *dev, struct dt_object *parent, - struct lu_fid *glb_fid, + const struct lu_fid *glb_fid, struct obd_uuid *uuid) { struct lquota_thread_info *qti = lquota_info(env); @@ -482,7 +478,7 @@ int lquota_disk_for_each_slv(const struct lu_env *env, struct dt_object *parent, int rc; ENTRY; - OBD_ALLOC(name, sizeof("0x00000000-")); + OBD_ALLOC(name, LQUOTA_NAME_MAX); if (name == NULL) RETURN(-ENOMEM); @@ -493,7 +489,7 @@ int lquota_disk_for_each_slv(const struct lu_env *env, struct dt_object *parent, iops = &parent->do_index_ops->dio_it; it = iops->init(env, parent, 0, BYPASS_CAPA); if (IS_ERR(it)) { - OBD_FREE(name, sizeof("0x00000000-")); + OBD_FREE(name, LQUOTA_NAME_MAX); RETURN(PTR_ERR(it)); } @@ -556,7 +552,7 @@ next: iops->put(env, it); iops->fini(env, it); - OBD_FREE(name, sizeof("0x00000000-")); + OBD_FREE(name, LQUOTA_NAME_MAX); if (rc > 0) rc = 0; RETURN(rc); @@ -741,3 +737,69 @@ out: dt_trans_stop(env, dev, th); return rc; } + +/* + * Write a global record + * + * \param env - is the environment passed by the caller + * \param obj - is the on-disk global index to be updated + * \param id - index to be updated + * \param rec - record to be written + */ +int lquota_disk_write_glb(const struct lu_env *env, struct dt_object *obj, + __u64 id, struct lquota_glb_rec *rec) +{ + struct dt_device *dev = lu2dt_dev(obj->do_lu.lo_dev); + struct thandle *th; + struct dt_key *key = (struct dt_key *)&id; + int rc; + ENTRY; + + th = dt_trans_create(env, dev); + if (IS_ERR(th)) + RETURN(PTR_ERR(th)); + + /* the entry with 0 key can always be found in IAM file. */ + if (id == 0) { + rc = dt_declare_delete(env, obj, key, th); + if (rc) + GOTO(out, rc); + } + + rc = dt_declare_insert(env, obj, (struct dt_rec *)rec, key, th); + if (rc) + GOTO(out, rc); + + rc = dt_trans_start_local(env, dev, th); + if (rc) + GOTO(out, rc); + + dt_write_lock(env, obj, 0); + + if (id == 0) { + struct lquota_glb_rec *tmp; + + OBD_ALLOC_PTR(tmp); + if (tmp == NULL) + GOTO(out_lock, rc = -ENOMEM); + + rc = dt_lookup(env, obj, (struct dt_rec *)tmp, key, + BYPASS_CAPA); + + OBD_FREE_PTR(tmp); + if (rc == 0) { + rc = dt_delete(env, obj, key, th, BYPASS_CAPA); + if (rc) + GOTO(out_lock, rc); + } + rc = 0; + } + + rc = dt_insert(env, obj, (struct dt_rec *)rec, key, th, BYPASS_CAPA, 1); +out_lock: + dt_write_unlock(env, obj); +out: + dt_trans_stop(env, dev, th); + RETURN(rc); +} +EXPORT_SYMBOL(lquota_disk_write_glb);