+static errcode_t merge_usage(dict_t *dest, dict_t *src)
+{
+ dnode_t *n;
+ struct dquot *src_dq, *dest_dq;
+
+ for (n = dict_first(src); n; n = dict_next(src, n)) {
+ src_dq = dnode_get(n);
+ if (!src_dq)
+ continue;
+ dest_dq = get_dq(dest, src_dq->dq_id);
+ if (dest_dq == NULL)
+ return -ENOMEM;
+ dest_dq->dq_dqb.dqb_curspace += src_dq->dq_dqb.dqb_curspace;
+ dest_dq->dq_dqb.dqb_curinodes += src_dq->dq_dqb.dqb_curinodes;
+ }
+
+ return 0;
+}
+
+
+errcode_t quota_merge_and_update_usage(quota_ctx_t dest_qctx,
+ quota_ctx_t src_qctx)
+{
+ dict_t *dict;
+ enum quota_type qtype;
+ errcode_t retval = 0;
+
+ for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
+ dict = src_qctx->quota_dict[qtype];
+ if (!dict)
+ continue;
+ retval = merge_usage(dest_qctx->quota_dict[qtype], dict);
+ if (retval)
+ break;
+ }
+
+ return retval;
+}
+