Whamcloud - gitweb
LU-15694 quota: keep grace time while setting default limits
[fs/lustre-release.git] / lustre / quota / qmt_entry.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012, 2016, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * Author: Johann Lombardi <johann.lombardi@intel.com>
28  * Author: Niu    Yawei    <yawei.niu@intel.com>
29  */
30
31 #define DEBUG_SUBSYSTEM S_LQUOTA
32
33 #include "qmt_internal.h"
34
35 /*
36  * Initialize qmt-specific fields of quota entry.
37  *
38  * \param lqe - is the quota entry to initialize
39  * \param arg - is the pointer to the qmt_pool_info structure
40  */
41 static void qmt_lqe_init(struct lquota_entry *lqe, void *arg)
42 {
43         LASSERT(lqe_is_master(lqe));
44
45         lqe->lqe_revoke_time = 0;
46         init_rwsem(&lqe->lqe_sem);
47         mutex_init(&lqe->lqe_glbl_data_lock);
48 }
49
50 /* Apply the default quota setting to the specified quota entry
51  *
52  * \param env           - is the environment passed by the caller
53  * \param pool          - is the quota pool of the quota entry
54  * \param lqe           - is the lquota_entry object to apply default quota on
55  * \param create_record - if true, an global quota record will be created and
56  *                        write to the disk.
57  *
58  * \retval 0            : success
59  * \retval -ve          : other appropriate errors
60  */
61 int qmt_lqe_set_default(const struct lu_env *env, struct qmt_pool_info *pool,
62                         struct lquota_entry *lqe, bool create_record)
63 {
64         struct lquota_entry     *lqe_def;
65         int                     rc = 0;
66
67         ENTRY;
68
69         if (lqe->lqe_id.qid_uid == 0)
70                 RETURN(0);
71
72         lqe_def = pool->qpi_grace_lqe[lqe_qtype(lqe)];
73
74         LQUOTA_DEBUG(lqe, "inherit default quota");
75
76         lqe->lqe_is_default = true;
77         lqe->lqe_hardlimit = lqe_def->lqe_hardlimit;
78         lqe->lqe_softlimit = lqe_def->lqe_softlimit;
79
80         if (create_record) {
81                 lqe->lqe_uptodate = true;
82                 rc = qmt_set_with_lqe(env, pool->qpi_qmt, lqe, 0, 0,
83                                       LQUOTA_GRACE_FLAG(0, LQUOTA_FLAG_DEFAULT),
84                                       QIF_TIMES, true, false);
85
86                 if (rc != 0)
87                         LQUOTA_ERROR(lqe, "failed to create the global quota"
88                                      " record: %d", rc);
89         }
90
91         if (lqe->lqe_hardlimit == 0 && lqe->lqe_softlimit == 0)
92                 lqe->lqe_enforced = false;
93         else
94                 lqe->lqe_enforced = true;
95
96         RETURN(rc);
97 }
98
99 /*
100  * Update a lquota entry. This is done by reading quota settings from the global
101  * index. The lquota entry must be write locked.
102  *
103  * \param env - the environment passed by the caller
104  * \param lqe - is the quota entry to refresh
105  * \param arg - is the pointer to the qmt_pool_info structure
106  * \param find - don't create lqe on disk in case of ENOENT if true
107  */
108 static int qmt_lqe_read(const struct lu_env *env, struct lquota_entry *lqe,
109                         void *arg, bool find)
110 {
111         struct qmt_thread_info  *qti = qmt_info(env);
112         struct qmt_pool_info    *pool = (struct qmt_pool_info *)arg;
113         int                      rc;
114         ENTRY;
115
116         LASSERT(lqe_is_master(lqe));
117
118         /* read record from disk */
119         rc = lquota_disk_read(env, pool->qpi_glb_obj[lqe->lqe_site->lqs_qtype],
120                               &lqe->lqe_id, (struct dt_rec *)&qti->qti_glb_rec);
121
122         switch (rc) {
123         case -ENOENT:
124                 if (find)
125                         RETURN(-ENOENT);
126                 qmt_lqe_set_default(env, pool, lqe, true);
127                 break;
128         case 0:
129                 /* copy quota settings from on-disk record */
130                 lqe->lqe_granted   = qti->qti_glb_rec.qbr_granted;
131                 lqe->lqe_hardlimit = qti->qti_glb_rec.qbr_hardlimit;
132                 lqe->lqe_softlimit = qti->qti_glb_rec.qbr_softlimit;
133                 lqe->lqe_gracetime = LQUOTA_GRACE(qti->qti_glb_rec.qbr_time);
134
135                 if (lqe->lqe_hardlimit == 0 && lqe->lqe_softlimit == 0 &&
136                     (LQUOTA_FLAG(qti->qti_glb_rec.qbr_time) &
137                      LQUOTA_FLAG_DEFAULT))
138                         qmt_lqe_set_default(env, pool, lqe, false);
139                 break;
140         default:
141                 LQUOTA_ERROR(lqe, "failed to read quota entry from disk, rc:%d",
142                              rc);
143                 RETURN(rc);
144         }
145
146         if (lqe->lqe_id.qid_uid == 0 ||
147             (lqe->lqe_hardlimit == 0 && lqe->lqe_softlimit == 0))
148                 /* {hard,soft}limit=0 means no quota enforced */
149                 lqe->lqe_enforced = false;
150         else
151                 lqe->lqe_enforced  = true;
152
153         if (qmt_pool_global(pool))
154                 lqe->lqe_is_global = 1;
155
156         LQUOTA_DEBUG(lqe, "read");
157         RETURN(0);
158 }
159
160 /*
161  * Print lqe information for debugging.
162  *
163  * \param lqe - is the quota entry to debug
164  * \param arg - is the pointer to the qmt_pool_info structure
165  * \param msgdata - debug message
166  * \param fmt     - format of debug message
167  */
168 static void qmt_lqe_debug(struct lquota_entry *lqe, void *arg,
169                           struct libcfs_debug_msg_data *msgdata,
170                           struct va_format *vaf)
171 {
172         struct qmt_pool_info    *pool = (struct qmt_pool_info *)arg;
173
174         libcfs_debug_msg(msgdata,
175                          "%pV qmt:%s pool:%s-%s id:%llu enforced:%d hard:%llu soft:%llu granted:%llu time:%llu qunit: %llu edquot:%d may_rel:%llu revoke:%lld default:%s\n",
176                          vaf, pool->qpi_qmt->qmt_svname,
177                          RES_NAME(pool->qpi_rtype),
178                          pool->qpi_name,
179                          lqe->lqe_id.qid_uid, lqe->lqe_enforced,
180                          lqe->lqe_hardlimit, lqe->lqe_softlimit,
181                          lqe->lqe_granted, lqe->lqe_gracetime,
182                          lqe->lqe_qunit, lqe->lqe_edquot, lqe->lqe_may_rel,
183                          lqe->lqe_revoke_time,
184                          lqe->lqe_is_default ? "yes" : "no");
185 }
186
187 /*
188  * Vector of quota entry operations supported on the master
189  */
190 const struct lquota_entry_operations qmt_lqe_ops = {
191         .lqe_init       = qmt_lqe_init,
192         .lqe_read       = qmt_lqe_read,
193         .lqe_debug      = qmt_lqe_debug,
194 };
195
196 /*
197  * Reserve enough credits to update records in both the global index and
198  * the slave index identified by \slv_obj
199  *
200  * \param env     - is the environment passed by the caller
201  * \param lqe     - is the quota entry associated with the identifier
202  *                  subject to the change. If it is NULL lqes array is
203  *                  taken from env with qti_lqes_env(env).
204  * \param slv_obj - is the dt_object associated with the index file
205  * \param sync    - make transaction sync if true
206  */
207 struct thandle *qmt_trans_start_with_slv(const struct lu_env *env,
208                                          struct lquota_entry *lqe,
209                                          struct dt_object *slv_obj,
210                                          bool sync)
211 {
212         struct qmt_device       *qmt;
213         struct thandle          *th;
214         struct lquota_entry     **lqes;
215         struct qmt_lqe_restore  *restore;
216         int                      rc, i, lqes_cnt;
217         ENTRY;
218
219         restore = qti_lqes_rstr(env);
220         if (!lqe) {
221                 lqes_cnt = qti_lqes_cnt(env);
222                 lqes = qti_lqes(env);
223         } else {
224                 lqes_cnt = 1;
225                 lqes = &lqe;
226         }
227
228         /* qmt is the same for all lqes, so take it from the 1st */
229         qmt = lqe2qpi(lqes[0])->qpi_qmt;
230
231         if (slv_obj != NULL)
232                 LQUOTA_DEBUG(lqes[0], "declare write for slv "DFID,
233                              PFID(lu_object_fid(&slv_obj->do_lu)));
234
235         /* start transaction */
236         th = dt_trans_create(env, qmt->qmt_child);
237         if (IS_ERR(th))
238                 RETURN(th);
239
240         if (sync)
241                 /* quota settings on master are updated synchronously for the
242                  * time being */
243                 th->th_sync = 1;
244
245         /* reserve credits for global index update */
246         for (i = 0; i < lqes_cnt; i++) {
247                 rc = lquota_disk_declare_write(env, th,
248                                                LQE_GLB_OBJ(lqes[i]),
249                                                &lqes[i]->lqe_id);
250                 if (rc)
251                         GOTO(out, rc);
252         }
253
254         if (slv_obj != NULL) {
255                 /* reserve credits for slave index update */
256                 rc = lquota_disk_declare_write(env, th, slv_obj,
257                                                &lqes[0]->lqe_id);
258                 if (rc)
259                         GOTO(out, rc);
260         }
261
262         /* start transaction */
263         rc = dt_trans_start_local(env, qmt->qmt_child, th);
264         if (rc)
265                 GOTO(out, rc);
266
267         EXIT;
268 out:
269         if (rc) {
270                 dt_trans_stop(env, qmt->qmt_child, th);
271                 th = ERR_PTR(rc);
272                 LQUOTA_ERROR(lqes[0], "failed to slv declare write for "DFID
273                              ", rc:%d", PFID(lu_object_fid(&slv_obj->do_lu)),
274                              rc);
275         } else {
276                 for (i = 0; i < lqes_cnt; i++) {
277                         restore[i].qlr_hardlimit = lqes[i]->lqe_hardlimit;
278                         restore[i].qlr_softlimit = lqes[i]->lqe_softlimit;
279                         restore[i].qlr_gracetime = lqes[i]->lqe_gracetime;
280                         restore[i].qlr_granted   = lqes[i]->lqe_granted;
281                         restore[i].qlr_qunit     = lqes[i]->lqe_qunit;
282                 }
283         }
284         return th;
285 }
286
287 /*
288  * Reserve enough credits to update a record in the global index
289  *
290  * \param env     - is the environment passed by the caller
291  * \param lqe     - is the quota entry to be modified in the global index
292  * \param restore - is a temporary storage for current quota settings which will
293  *                  be restored if something goes wrong at index update time.
294  */
295 struct thandle *qmt_trans_start(const struct lu_env *env,
296                                 struct lquota_entry *lqe)
297 {
298         LQUOTA_DEBUG(lqe, "declare write");
299         return qmt_trans_start_with_slv(env, lqe, NULL, true);
300 }
301
302 int qmt_glb_write_lqes(const struct lu_env *env, struct thandle *th,
303                        __u32 flags, __u64 *ver)
304 {
305         int i, rc = 0;
306
307         for (i = 0; i < qti_lqes_cnt(env); i++) {
308                 rc = qmt_glb_write(env, th, qti_lqes(env)[i], flags, ver);
309                 if (rc)
310                         break;
311         }
312         return rc;
313 }
314
315 /*
316  * Update record associated with a quota entry in the global index.
317  * If LQUOTA_BUMP_VER is set, then the global index version must also be
318  * bumped.
319  * The entry must be at least read locked, dirty and up-to-date.
320  *
321  * \param env   - the environment passed by the caller
322  * \param th    - is the transaction handle to be used for the disk writes
323  * \param lqe   - is the quota entry to udpate
324  * \param obj   - is the dt_object associated with the index file
325  * \param flags - can be LQUOTA_BUMP_VER or LQUOTA_SET_VER.
326  * \param ver   - is used to return the new version of the index.
327  *
328  * \retval      - 0 on success and lqe dirty flag cleared,
329  *                appropriate error on failure and uptodate flag cleared.
330  */
331 int qmt_glb_write(const struct lu_env *env, struct thandle *th,
332                   struct lquota_entry *lqe, __u32 flags, __u64 *ver)
333 {
334         struct qmt_thread_info  *qti = qmt_info(env);
335         struct lquota_glb_rec   *rec;
336         int                      rc;
337         ENTRY;
338
339         LASSERT(lqe != NULL);
340         LASSERT(lqe_is_master(lqe));
341         LASSERT(lqe_is_locked(lqe));
342         LASSERT(lqe->lqe_uptodate);
343         LASSERT((flags & ~(LQUOTA_BUMP_VER | LQUOTA_SET_VER)) == 0);
344
345         LQUOTA_DEBUG(lqe, "write glb");
346
347         /* never delete the entry even when the id isn't enforced and
348          * no any guota granted, otherwise, this entry will not be
349          * synced to slave during the reintegration. */
350         rec = &qti->qti_glb_rec;
351
352         /* fill global index with updated quota settings */
353         rec->qbr_granted   = lqe->lqe_granted;
354         if (lqe->lqe_is_default) {
355                 rec->qbr_hardlimit = 0;
356                 rec->qbr_softlimit = 0;
357                 rec->qbr_time      = LQUOTA_GRACE_FLAG(lqe->lqe_gracetime,
358                                                        LQUOTA_FLAG_DEFAULT);
359         } else {
360                 rec->qbr_hardlimit = lqe->lqe_hardlimit;
361                 rec->qbr_softlimit = lqe->lqe_softlimit;
362                 rec->qbr_time      = lqe->lqe_gracetime;
363         }
364
365         /* write new quota settings */
366         rc = lquota_disk_write(env, th, LQE_GLB_OBJ(lqe), &lqe->lqe_id,
367                                (struct dt_rec *)rec, flags, ver);
368         if (rc)
369                 /* we failed to write the new quota settings to disk, report
370                  * error to caller who will restore the initial value */
371                 LQUOTA_ERROR(lqe, "failed to update global index, rc:%d", rc);
372
373         RETURN(rc);
374 }
375
376 /*
377  * Read from disk how much quota space is allocated to a slave.
378  * This is done by reading records from the dedicated slave index file.
379  * Return in \granted how much quota space is currently allocated to the
380  * slave.
381  * The entry must be at least read locked.
382  *
383  * \param env - the environment passed by the caller
384  * \param lqe_id - is the quota id associated with the identifier to look-up
385  *              in the slave index
386  * \param slv_obj - is the dt_object associated with the slave index
387  * \param granted - is the output parameter where to return how much space
388  *                  is granted to the slave.
389  *
390  * \retval    - 0 on success, appropriate error on failure
391  */
392 int qmt_slv_read(const struct lu_env *env, union lquota_id *qid,
393                  struct dt_object *slv_obj, __u64 *granted)
394 {
395         struct qmt_thread_info  *qti = qmt_info(env);
396         struct lquota_slv_rec   *slv_rec = &qti->qti_slv_rec;
397         int                      rc;
398         ENTRY;
399
400         CDEBUG(D_QUOTA, "read id:%llu form slv "DFID"\n",
401                qid->qid_uid, PFID(lu_object_fid(&slv_obj->do_lu)));
402
403         /* read slave record from disk */
404         rc = lquota_disk_read(env, slv_obj, qid,
405                               (struct dt_rec *)slv_rec);
406         switch (rc) {
407         case -ENOENT:
408                 *granted = 0;
409                 break;
410         case 0:
411                 /* extract granted from on-disk record */
412                 *granted = slv_rec->qsr_granted;
413                 break;
414         default:
415                 CERROR("Failed to read slave record for %llu from "DFID"\n",
416                        qid->qid_uid, PFID(lu_object_fid(&slv_obj->do_lu)));
417                 RETURN(rc);
418         }
419
420         CDEBUG(D_QUOTA, "Successful slv read %llu\n", *granted);
421
422         RETURN(0);
423 }
424
425 /*
426  * Update record in slave index file.
427  * The entry must be at least read locked.
428  *
429  * \param env - the environment passed by the caller
430  * \param th  - is the transaction handle to be used for the disk writes
431  * \param lqe - is the dirty quota entry which will be updated at the same time
432  *              as the slave index
433  * \param slv_obj - is the dt_object associated with the slave index
434  * \param flags - can be LQUOTA_BUMP_VER or LQUOTA_SET_VER.
435  * \param ver   - is used to return the new version of the index.
436  * \param granted - is the new amount of quota space owned by the slave
437  *
438  * \retval    - 0 on success, appropriate error on failure
439  */
440 int qmt_slv_write(const struct lu_env *env, struct thandle *th,
441                   struct lquota_entry *lqe, struct dt_object *slv_obj,
442                   __u32 flags, __u64 *ver, __u64 granted)
443 {
444         struct qmt_thread_info  *qti = qmt_info(env);
445         struct lquota_slv_rec   *rec;
446         int                      rc;
447         ENTRY;
448
449         LASSERT(lqe != NULL);
450         LASSERT(lqe_is_master(lqe));
451         LASSERT(lqe_is_locked(lqe));
452
453         LQUOTA_DEBUG(lqe, "write slv "DFID" granted:%llu",
454                      PFID(lu_object_fid(&slv_obj->do_lu)), granted);
455
456         /* never delete the entry, otherwise, it'll not be transferred
457          * to slave during reintegration. */
458         rec = &qti->qti_slv_rec;
459
460         /* updated space granted to this slave */
461         rec->qsr_granted = granted;
462
463         /* write new granted space */
464         rc = lquota_disk_write(env, th, slv_obj, &lqe->lqe_id,
465                                (struct dt_rec *)rec, flags, ver);
466         if (rc) {
467                 LQUOTA_ERROR(lqe,
468                              "failed to update slave index "DFID" granted:%llu",
469                              PFID(lu_object_fid(&slv_obj->do_lu)),
470                              granted);
471                 RETURN(rc);
472         }
473
474         RETURN(0);
475 }
476
477 /*
478  * Check whether new limits are valid for this pool
479  *
480  * \param lqe  - is the quota entry subject to the setquota
481  * \param hard - is the new hard limit
482  * \param soft - is the new soft limit
483  */
484 int qmt_validate_limits(struct lquota_entry *lqe, __u64 hard, __u64 soft)
485 {
486         ENTRY;
487
488         if (hard != 0 && soft > hard)
489                 /* soft limit must be less than hard limit */
490                 RETURN(-EINVAL);
491         RETURN(0);
492 }
493
494 /*
495  * Set/clear edquot flag after quota space allocation/release or settings
496  * change. Slaves will be notified of changes via glimpse on per-ID lock
497  *
498  * \param lqe - is the quota entry to check
499  * \param now - is the current time in second used for grace time managment
500  */
501 bool qmt_adjust_edquot(struct lquota_entry *lqe, __u64 now)
502 {
503         struct qmt_pool_info    *pool = lqe2qpi(lqe);
504         ENTRY;
505
506         if (!lqe->lqe_enforced || lqe->lqe_id.qid_uid == 0)
507                 RETURN(false);
508
509         if (!lqe->lqe_edquot) {
510                 /* space exhausted flag not set, let's check whether it is time
511                  * to set the flag */
512
513                 if (!qmt_space_exhausted(lqe, now))
514                         /* the qmt still has available space */
515                         RETURN(false);
516
517                 /* See comment in qmt_adjust_qunit(). LU-4139 */
518                 if (qmt_hard_exhausted(lqe) ||
519                     pool->qpi_rtype != LQUOTA_RES_DT) {
520                         time64_t lapse;
521
522                         /* we haven't reached the minimal qunit yet so there is
523                          * still hope that the rebalancing process might free
524                          * up some quota space */
525                         if (lqe->lqe_qunit != pool->qpi_least_qunit)
526                                 RETURN(false);
527
528                         /* least qunit value not sent to all slaves yet */
529                         if (lqe->lqe_revoke_time == 0)
530                                 RETURN(false);
531
532                         /* Let's give more time to slave to release space */
533                         lapse = ktime_get_seconds() - QMT_REBA_TIMEOUT;
534                         if (lqe->lqe_may_rel != 0 && lqe->lqe_revoke_time > lapse)
535                                 RETURN(false);
536                 } else {
537                         if (lqe->lqe_qunit > pool->qpi_soft_least_qunit)
538                                 RETURN(false);
539                 }
540
541                 /* set edquot flag */
542                 lqe->lqe_edquot = true;
543         } else {
544                 /* space exhausted flag set, let's check whether it is time to
545                  * clear it */
546
547                 if (qmt_space_exhausted(lqe, now))
548                         /* the qmt still has not space */
549                         RETURN(false);
550
551                 if (lqe->lqe_hardlimit != 0 &&
552                     lqe->lqe_granted + pool->qpi_least_qunit >
553                                                         lqe->lqe_hardlimit)
554                         /* we clear the flag only once at least one least qunit
555                          * is available */
556                         RETURN(false);
557
558                 /* clear edquot flag */
559                 lqe->lqe_edquot = false;
560         }
561
562         LQUOTA_DEBUG(lqe, "changing edquot flag");
563
564         /* let's notify slave by issuing glimpse on per-ID lock.
565          * the rebalance thread will take care of this */
566         RETURN(true);
567 }
568
569 /* Using least_qunit when over block softlimit will seriously impact the
570  * write performance, we need to do some special tweaking on that. */
571 static __u64 qmt_calc_softlimit(struct lquota_entry *lqe, bool *oversoft)
572 {
573         struct qmt_pool_info *pool = lqe2qpi(lqe);
574
575         LASSERT(lqe->lqe_softlimit != 0);
576         *oversoft = false;
577         /* No need to do special tweaking for inode limit */
578         if (pool->qpi_rtype != LQUOTA_RES_DT)
579                 return lqe->lqe_softlimit;
580
581         if (lqe->lqe_granted <= lqe->lqe_softlimit +
582                                 pool->qpi_soft_least_qunit) {
583                 return lqe->lqe_softlimit;
584         } else if (lqe->lqe_hardlimit != 0) {
585                 *oversoft = true;
586                 return lqe->lqe_hardlimit;
587         } else {
588                 *oversoft = true;
589                 return 0;
590         }
591 }
592
593 /*
594  * Try to grant more quota space back to slave.
595  *
596  * \param lqe     - is the quota entry for which we would like to allocate more
597  *                  space
598  * \param granted - is how much was already granted as part of the request
599  *                  processing
600  * \param spare   - is how much unused quota space the slave already owns
601  *
602  * \retval return how additional space can be granted to the slave
603  */
604 __u64 qmt_alloc_expand(struct lquota_entry *lqe, __u64 granted, __u64 spare)
605 {
606         struct qmt_pool_info    *pool = lqe2qpi(lqe);
607         __u64                    remaining, qunit;
608         int                      slv_cnt;
609
610         LASSERT(lqe->lqe_enforced && lqe->lqe_qunit != 0);
611
612         slv_cnt = qpi_slv_nr(lqe2qpi(lqe), lqe_qtype(lqe));
613         qunit = lqe->lqe_qunit;
614
615         /* See comment in qmt_adjust_qunit(). LU-4139. */
616         if (lqe->lqe_softlimit != 0) {
617                 bool oversoft;
618                 remaining = qmt_calc_softlimit(lqe, &oversoft);
619                 if (remaining == 0)
620                         remaining = lqe->lqe_granted +
621                                     pool->qpi_soft_least_qunit;
622         } else {
623                 remaining = lqe->lqe_hardlimit;
624         }
625
626         if (lqe->lqe_granted >= remaining)
627                 RETURN(0);
628
629         remaining -= lqe->lqe_granted;
630
631         do {
632                 if (spare >= qunit)
633                         break;
634
635                 granted &= (qunit - 1);
636
637                 if (remaining > (slv_cnt * qunit) >> 1) {
638                         /* enough room to grant more space w/o additional
639                          * shrinking ... at least for now */
640                         remaining -= (slv_cnt * qunit) >> 1;
641                 } else if (qunit != pool->qpi_least_qunit) {
642                         qunit >>= 2;
643                         continue;
644                 }
645
646                 granted &= (qunit - 1);
647                 if (spare > 0)
648                         RETURN(min_t(__u64, qunit - spare, remaining));
649                 else
650                         RETURN(min_t(__u64, qunit - granted, remaining));
651         } while (qunit >= pool->qpi_least_qunit);
652
653         RETURN(0);
654 }
655
656 static inline void
657 qmt_adjust_qunit_set_revoke(const struct lu_env *env, struct lquota_entry *lqe,
658                             unsigned long least_qunit)
659 {
660         struct lquota_entry *lqe2;
661         time64_t min = 0;
662         int i;
663
664         if (qti_lqes_cnt(env) <= 1)
665                 return;
666
667         for (i = 0; i < qti_lqes_cnt(env); i++) {
668                 lqe2 = qti_lqes(env)[i];
669                 if ((lqe2->lqe_qunit == least_qunit) && lqe2->lqe_revoke_time) {
670                         if (!min) {
671                                 min = lqe2->lqe_revoke_time;
672                                 continue;
673                         }
674                         min = lqe2->lqe_revoke_time < min ?
675                                 lqe2->lqe_revoke_time : min;
676                 }
677         }
678
679         lqe->lqe_revoke_time = min;
680 }
681
682
683 /*
684  * Adjust qunit size according to quota limits and total granted count.
685  * The caller must have locked the lqe.
686  *
687  * \param env - the environment passed by the caller
688  * \param lqe - is the qid entry to be adjusted
689  * \retval true - need reseed glbe array
690  */
691 bool qmt_adjust_qunit(const struct lu_env *env, struct lquota_entry *lqe)
692 {
693         struct qmt_pool_info    *pool = lqe2qpi(lqe);
694         bool                     need_reseed = false;
695         int                      slv_cnt;
696         __u64                    qunit, limit, qunit2 = 0;
697         ENTRY;
698
699         LASSERT(lqe_is_locked(lqe));
700
701         if (!lqe->lqe_enforced || lqe->lqe_id.qid_uid == 0)
702                 /* no quota limits */
703                 RETURN(need_reseed);
704
705         /* record how many slaves have already registered */
706         slv_cnt = qpi_slv_nr(pool, lqe_qtype(lqe));
707         if (slv_cnt == 0) {
708                 /* Pool hasn't slaves anymore. Qunit will be adjusted
709                  * again when new slaves would be added. */
710                 if (lqe->lqe_qunit) {
711                         qunit = 0;
712                         GOTO(done, qunit);
713                 }
714                 /* wait for at least one slave to join */
715                 RETURN(need_reseed);
716         }
717
718         /* Qunit calculation is based on soft limit, if any, hard limit
719          * otherwise. This means that qunit is shrunk to the minimum when
720          * beyond the soft limit. This will impact performance, but that's the
721          * price of an accurate grace time management. */
722         if (lqe->lqe_softlimit != 0) {
723                 bool oversoft;
724                 /* As a compromise of write performance and the grace time
725                  * accuracy, the block qunit size will be shrunk to
726                  * qpi_soft_least_qunit when over softlimit. LU-4139. */
727                 limit = qmt_calc_softlimit(lqe, &oversoft);
728                 if (oversoft)
729                         qunit2 = pool->qpi_soft_least_qunit;
730                 if (limit == 0)
731                         GOTO(done, qunit = qunit2);
732         } else if (lqe->lqe_hardlimit != 0) {
733                 limit = lqe->lqe_hardlimit;
734         } else {
735                 LQUOTA_ERROR(lqe, "enforced bit set, but neither hard nor soft "
736                              "limit are set");
737                 RETURN(need_reseed);
738         }
739
740         qunit = lqe->lqe_qunit == 0 ? pool->qpi_least_qunit : lqe->lqe_qunit;
741
742         /* The qunit value is computed as follows: limit / (2 * slv_cnt).
743          * Then 75% of the quota space can be granted with current qunit value.
744          * The remaining 25% are then used with reduced qunit size (by a factor
745          * of 4) which is then divided in a similar manner.
746          *
747          * |---------------------limit---------------------|
748          * |-------limit / 2-------|-limit / 4-|-limit / 4-|
749          * |qunit|qunit|qunit|qunit|           |           |
750          * |----slv_cnt * qunit----|           |           |
751          * |-grow limit-|          |           |           |
752          * |--------------shrink limit---------|           |
753          * |---space granted in qunit chunks---|-remaining-|
754          *                                    /             \
755          *                                   /               \
756          *                                  /                 \
757          *                                 /                   \
758          *                                /                     \
759          *     qunit >>= 2;            |qunit*slv_cnt|qunit*slv_cnt|
760          *                             |---space in qunit---|remain|
761          *                                  ...                               */
762         if (qunit == pool->qpi_least_qunit ||
763             limit >= lqe->lqe_granted + ((slv_cnt * qunit) >> 1)) {
764                 /* current qunit value still fits, let's see if we can afford to
765                  * increase qunit now ...
766                  * To increase qunit again, we have to be under 25% */
767                 while (qunit && limit >= lqe->lqe_granted + 6 * qunit * slv_cnt)
768                         qunit <<= 2;
769
770                 if (!qunit) {
771                         qunit = limit;
772                         do_div(qunit, 2 * slv_cnt);
773                 }
774
775         } else {
776                 /* shrink qunit until we find a suitable value */
777                 while (qunit > pool->qpi_least_qunit &&
778                        limit < lqe->lqe_granted + ((slv_cnt * qunit) >> 1))
779                         qunit >>= 2;
780         }
781
782         if (qunit2 && qunit > qunit2)
783                 qunit = qunit2;
784 done:
785         if (lqe->lqe_qunit == qunit)
786                 /* keep current qunit */
787                 RETURN(need_reseed);
788
789         LQUOTA_DEBUG(lqe, "%s qunit to %llu",
790                      lqe->lqe_qunit < qunit ? "increasing" : "decreasing",
791                      qunit);
792
793         /* store new qunit value */
794         swap(lqe->lqe_qunit, qunit);
795
796         /* reseed glbe array and notify
797          * slave if qunit was shrinked */
798         need_reseed = true;
799         /* reset revoke time */
800         lqe->lqe_revoke_time = 0;
801
802         if (lqe->lqe_qunit == pool->qpi_least_qunit) {
803                 if (lqe->lqe_qunit >= qunit)
804                         /* initial qunit value is the smallest one */
805                         lqe->lqe_revoke_time = ktime_get_seconds();
806                 /* If there are several lqes and lqe_revoke_time is set for
807                  * some of them, it means appropriate OSTs have been already
808                  * notified with the least qunit and there is no chance to
809                  * free more space. Find an lqe with the minimum(earliest)
810                  * revoke_time and set this time to the current one.
811                  */
812                 qmt_adjust_qunit_set_revoke(env, lqe, pool->qpi_least_qunit);
813         }
814         RETURN(need_reseed);
815 }
816
817 bool qmt_adjust_edquot_qunit_notify(const struct lu_env *env,
818                                     struct qmt_device *qmt,
819                                     __u64 now, bool edquot,
820                                     bool qunit, __u32 qb_flags)
821 {
822         struct lquota_entry *lqe_gl, *lqe;
823         bool need_reseed = false;
824         int i;
825
826         lqe_gl = qti_lqes_glbl(env);
827
828         for (i = 0; i < qti_lqes_cnt(env); i++) {
829                 lqe = qti_lqes(env)[i];
830                 if (qunit)
831                         need_reseed |= qmt_adjust_qunit(env, lqe);
832                 if (edquot)
833                         need_reseed |= qmt_adjust_edquot(lqe, now);
834         }
835
836         LASSERT(lqe_gl);
837         if (!lqe_gl->lqe_glbl_data &&
838             (req_has_rep(qb_flags) || req_is_rel(qb_flags))) {
839                 if (need_reseed)
840                         CDEBUG(D_QUOTA,
841                                "%s: can not notify - lge_glbl_data is not set\n",
842                                qmt->qmt_svname);
843                 return need_reseed;
844         }
845
846         if (need_reseed) {
847                 mutex_lock(&lqe_gl->lqe_glbl_data_lock);
848                 if (lqe_gl->lqe_glbl_data)
849                         qmt_seed_glbe_all(env, lqe_gl->lqe_glbl_data, qunit,
850                                           edquot);
851                 mutex_unlock(&lqe_gl->lqe_glbl_data_lock);
852
853                 qmt_id_lock_notify(qmt, lqe_gl);
854         }
855         return need_reseed;
856 }
857
858
859 /*
860  * Adjust qunit & edquot flag in case it wasn't initialized already (e.g.
861  * limit set while no slaves were connected yet)
862  */
863 bool qmt_revalidate(const struct lu_env *env, struct lquota_entry *lqe)
864 {
865         bool need_notify = false;
866
867         if (lqe->lqe_qunit == 0) {
868                 /* lqe was read from disk, but neither qunit, nor edquot flag
869                  * were initialized */
870                 need_notify = qmt_adjust_qunit(env, lqe);
871                 if (lqe->lqe_qunit != 0)
872                         need_notify |= qmt_adjust_edquot(lqe,
873                                                 ktime_get_real_seconds());
874         }
875
876         return need_notify;
877 }
878
879 void qmt_revalidate_lqes(const struct lu_env *env,
880                          struct qmt_device *qmt, __u32 qb_flags)
881 {
882         struct lquota_entry *lqe_gl = qti_lqes_glbl(env);
883         bool need_notify = false;
884         int i;
885
886         for (i = 0; i < qti_lqes_cnt(env); i++)
887                 need_notify |= qmt_revalidate(env, qti_lqes(env)[i]);
888
889         if (!need_notify)
890                 return;
891
892         /* There could be no ID lock to the moment of reconciliation.
893          * As a result lqe global data is not initialised yet. It is ok
894          * for release and report requests. */
895         if (!lqe_gl->lqe_glbl_data &&
896             (req_is_rel(qb_flags) || req_has_rep(qb_flags))) {
897                 return;
898         }
899
900         mutex_lock(&lqe_gl->lqe_glbl_data_lock);
901         if (lqe_gl->lqe_glbl_data)
902                 qmt_seed_glbe(env, lqe_gl->lqe_glbl_data);
903         mutex_unlock(&lqe_gl->lqe_glbl_data_lock);
904
905         qmt_id_lock_notify(qmt, lqe_gl);
906 }
907
908 void qti_lqes_init(const struct lu_env *env)
909 {
910         struct qmt_thread_info  *qti = qmt_info(env);
911
912         qti->qti_lqes_cnt = 0;
913         qti->qti_glbl_lqe_idx = 0;
914         qti->qti_lqes_num = QMT_MAX_POOL_NUM;
915 }
916
917 int qti_lqes_add(const struct lu_env *env, struct lquota_entry *lqe)
918 {
919         struct qmt_thread_info  *qti = qmt_info(env);
920
921         if (qti->qti_lqes_cnt >= qti->qti_lqes_num) {
922                 struct lquota_entry     **lqes;
923                 lqes = qti->qti_lqes;
924                 OBD_ALLOC(lqes, sizeof(lqe) * qti->qti_lqes_num * 2);
925                 if (!lqes)
926                         return -ENOMEM;
927                 memcpy(lqes, qti_lqes(env), qti->qti_lqes_cnt * sizeof(lqe));
928                 /* Don't need to free, if it is the very 1st allocation */
929                 if (qti->qti_lqes_num > QMT_MAX_POOL_NUM)
930                         OBD_FREE(qti->qti_lqes,
931                                  qti->qti_lqes_num * sizeof(lqe));
932                 qti->qti_lqes = lqes;
933                 qti->qti_lqes_num *= 2;
934         }
935
936         if (lqe->lqe_is_global)
937                 qti->qti_glbl_lqe_idx = qti->qti_lqes_cnt;
938         qti_lqes(env)[qti->qti_lqes_cnt++] = lqe;
939
940         /* The pool could be accessed directly from lqe, so take
941          * extra reference that is put in qti_lqes_fini */
942         qpi_getref(lqe2qpi(lqe));
943
944         CDEBUG(D_QUOTA, "LQE %p %lu is added, lqe_cnt %d lqes_num %d\n",
945                          lqe, (long unsigned)lqe->lqe_id.qid_uid,
946                          qti->qti_lqes_cnt, qti->qti_lqes_num);
947         LASSERT(qti->qti_lqes_num != 0);
948
949         return 0;
950 }
951
952 void qti_lqes_del(const struct lu_env *env, int index)
953 {
954         struct lquota_entry     **lqes;
955         int lqes_cnt = qti_lqes_cnt(env);
956         int lqep_size = sizeof(struct lquota_entry *);
957
958         if (index == 0) {
959                 /* We can't handle non global lqes correctly without
960                  * global lqe located at index 0. If we try to do so,
961                  * something goes wrong. */
962                 LQUOTA_ERROR(qti_lqes_glbl(env),
963                              "quota: cannot remove lqe at index 0 as it is global");
964                 LASSERT(qti_lqes_glbl(env)->lqe_is_global);
965                 return;
966         }
967         lqes = qti_lqes(env);
968         qpi_putref(env, lqe2qpi(lqes[index]));
969         lqe_putref(lqes[index]);
970         memcpy((unsigned char *)lqes + index * lqep_size,
971                (unsigned char *)lqes + (index + 1) * lqep_size,
972                (lqes_cnt - index - 1) * lqep_size);
973         qti_lqes_cnt(env)--;
974 }
975
976 void qti_lqes_fini(const struct lu_env *env)
977 {
978         struct qmt_thread_info  *qti = qmt_info(env);
979         struct lquota_entry     **lqes = qti->qti_lqes;
980         int i;
981
982         lqes = qti_lqes(env);
983         for (i = 0; i < qti->qti_lqes_cnt; i++) {
984                 qpi_putref(env, lqe2qpi(lqes[i]));
985                 lqe_putref(lqes[i]);
986         }
987
988         if (qti->qti_lqes_num > QMT_MAX_POOL_NUM)
989                 OBD_FREE(qti->qti_lqes,
990                          qti->qti_lqes_num * sizeof(struct lquota_entry *));
991
992         qti->qti_lqes_num = 0;
993         qti->qti_lqes_cnt = 0;
994 }
995
996 __u64 qti_lqes_min_qunit(const struct lu_env *env)
997 {
998         __u64 min, qunit;
999         int i;
1000
1001         for (i = 1, min = qti_lqe_qunit(env, 0); i < qti_lqes_cnt(env); i++) {
1002                 qunit = qti_lqe_qunit(env, i);
1003                 /* if qunit is 0, lqe is not enforced and we can ignore it */
1004                 if (qunit && qunit < min)
1005                         min = qunit;
1006         }
1007
1008         return min;
1009 }
1010
1011 int qti_lqes_edquot(const struct lu_env *env)
1012 {
1013         int i;
1014
1015         for (i = 0; i < qti_lqes_cnt(env); i++) {
1016                 if (qti_lqes(env)[i]->lqe_edquot)
1017                         return 1;
1018         }
1019
1020         return 0;
1021 }
1022
1023 int qti_lqes_restore_init(const struct lu_env *env)
1024 {
1025         int rc = 0;
1026
1027         if (qti_lqes_inited(env) && qti_lqes_cnt(env) > QMT_MAX_POOL_NUM) {
1028                 OBD_ALLOC(qmt_info(env)->qti_lqes_rstr,
1029                           qti_lqes_cnt(env) * sizeof(struct qmt_lqe_restore));
1030                 if (!qti_lqes_rstr(env))
1031                         rc = -ENOMEM;
1032         }
1033
1034         return rc;
1035 }
1036
1037 void qti_lqes_restore_fini(const struct lu_env *env)
1038 {
1039         if (qti_lqes_inited(env) && qti_lqes_cnt(env) > QMT_MAX_POOL_NUM)
1040                 OBD_FREE(qmt_info(env)->qti_lqes_rstr,
1041                          qti_lqes_cnt(env) * sizeof(struct qmt_lqe_restore));
1042 }
1043
1044 void qti_lqes_write_lock(const struct lu_env *env)
1045 {
1046         int i;
1047
1048         for (i = 0; i < qti_lqes_cnt(env); i++)
1049                 lqe_write_lock(qti_lqes(env)[i]);
1050 }
1051
1052 void qti_lqes_write_unlock(const struct lu_env *env)
1053 {
1054         int i;
1055
1056         for (i = 0; i < qti_lqes_cnt(env); i++)
1057                 lqe_write_unlock(qti_lqes(env)[i]);
1058 }
1059
1060 #define QMT_INIT_SLV_CNT        64
1061 struct lqe_glbl_data *qmt_alloc_lqe_gd(struct qmt_pool_info *pool, int qtype)
1062 {
1063         struct lqe_glbl_data    *lgd;
1064         struct lqe_glbl_entry   *lqeg_arr;
1065         int                      slv_cnt, glbe_num;
1066
1067         OBD_ALLOC(lgd, sizeof(struct lqe_glbl_data));
1068         if (!lgd)
1069                 RETURN(NULL);
1070
1071         slv_cnt = qpi_slv_nr_by_rtype(pool, qtype);
1072
1073         glbe_num = slv_cnt < QMT_INIT_SLV_CNT ? QMT_INIT_SLV_CNT : slv_cnt;
1074         OBD_ALLOC(lqeg_arr, sizeof(struct lqe_glbl_entry) * glbe_num);
1075         if (!lqeg_arr) {
1076                 OBD_FREE(lgd, sizeof(struct lqe_glbl_data));
1077                 RETURN(NULL);
1078         }
1079
1080         CDEBUG(D_QUOTA, "slv_cnt %d glbe_num %d\n", slv_cnt, glbe_num);
1081
1082         lgd->lqeg_num_used = slv_cnt;
1083         lgd->lqeg_num_alloc = glbe_num;
1084         lgd->lqeg_arr = lqeg_arr;
1085
1086         RETURN(lgd);
1087 }
1088
1089 void qmt_free_lqe_gd(struct lqe_glbl_data *lgd)
1090 {
1091         OBD_FREE(lgd->lqeg_arr,
1092                  sizeof(struct lqe_glbl_entry) * lgd->lqeg_num_alloc);
1093         OBD_FREE(lgd, sizeof(struct lqe_glbl_data));
1094 }
1095
1096 void qmt_seed_glbe_all(const struct lu_env *env, struct lqe_glbl_data *lgd,
1097                        bool qunit, bool edquot)
1098 {
1099         struct rw_semaphore     *sem = NULL;
1100         struct qmt_pool_info    *qpi;
1101         int                      i, j, idx;
1102         ENTRY;
1103
1104         if (!qti_lqes_cnt(env))
1105                 RETURN_EXIT;
1106         /* lqes array is sorted by qunit - the first entry has minimum qunit.
1107          * Thus start seeding global qunit's array beginning from the 1st lqe
1108          * and appropriate pool. If pools overlapped, slaves from this
1109          * overlapping get minimum qunit value.
1110          * user1: pool1, pool2, pool_glbl;
1111          * pool1: OST1; user1_qunit = 10M;
1112          * pool2: OST0, OST1, OST2; user1_qunit = 30M;
1113          * pool_glbl: OST0, OST1, OST2, OST3; user1_qunit = 160M;
1114          * qunit array after seeding should be:
1115          * OST0: 30M; OST1: 10M; OST2: 30M; OST3: 160M; */
1116
1117         /* edquot resetup algorythm works fine
1118          * with not sorted lqes */
1119         if (qunit)
1120                 qmt_lqes_sort(env);
1121
1122         for (i = 0; i < lgd->lqeg_num_used; i++) {
1123                 lgd->lqeg_arr[i].lge_qunit_set = 0;
1124                 lgd->lqeg_arr[i].lge_qunit_nu = 0;
1125                 lgd->lqeg_arr[i].lge_edquot_nu = 0;
1126         }
1127
1128         for (i = 0; i < qti_lqes_cnt(env); i++) {
1129                 struct lquota_entry *lqe = qti_lqes(env)[i];
1130                 int slaves_cnt;
1131
1132                 CDEBUG(D_QUOTA, "lqes_cnt %d, i %d\n", qti_lqes_cnt(env), i);
1133                 qpi = lqe2qpi(lqe);
1134                 if (qmt_pool_global(qpi)) {
1135                         slaves_cnt = qpi_slv_nr_by_rtype(lqe2qpi(lqe),
1136                                                          lqe_qtype(lqe));
1137                 } else {
1138                         sem = qmt_sarr_rwsem(qpi);
1139                         down_read(sem);
1140                         slaves_cnt = qmt_sarr_count(qpi);
1141                 }
1142
1143                 for (j = 0; j < slaves_cnt; j++) {
1144                         idx = qmt_sarr_get_idx(qpi, j);
1145                         LASSERT(idx >= 0);
1146
1147                         if (edquot) {
1148                                 int lge_edquot, new_edquot, edquot_nu;
1149
1150                                 lge_edquot = lgd->lqeg_arr[idx].lge_edquot;
1151                                 edquot_nu = lgd->lqeg_arr[idx].lge_edquot_nu;
1152                                 new_edquot = lqe->lqe_edquot;
1153
1154                                 if (lge_edquot == new_edquot ||
1155                                     (edquot_nu && lge_edquot == 1))
1156                                         goto qunit_lbl;
1157                                 lgd->lqeg_arr[idx].lge_edquot = new_edquot;
1158                                 /* it is needed for the following case:
1159                                  * initial values for idx i -
1160                                  * lqe_edquot = 1, lqe_edquot_nu == 0;
1161                                  * 1: new_edquot == 0 ->
1162                                  *      lqe_edquot = 0, lqe_edquot_nu = 1;
1163                                  * 2: new_edquot == 1 ->
1164                                  *      lqe_edquot = 1, lqe_edquot_nu = 0;
1165                                  * At the 2nd iteration lge_edquot comes back
1166                                  * to 1, so no changes and we don't need
1167                                  * to notify slave. */
1168                                 lgd->lqeg_arr[idx].lge_edquot_nu = !edquot_nu;
1169                         }
1170 qunit_lbl:
1171                         if (qunit) {
1172                                 __u64 lge_qunit, new_qunit;
1173
1174                                 CDEBUG(D_QUOTA,
1175                                        "idx %d lge_qunit_set %d lge_qunit %llu new_qunit %llu\n",
1176                                        idx, lgd->lqeg_arr[idx].lge_qunit_set,
1177                                        lgd->lqeg_arr[idx].lge_qunit,
1178                                        lqe->lqe_qunit);
1179                                 /* lge for this idx is already set
1180                                  * on previous iteration */
1181                                 if (lgd->lqeg_arr[idx].lge_qunit_set)
1182                                         continue;
1183                                 lge_qunit = lgd->lqeg_arr[idx].lge_qunit;
1184                                 new_qunit = lqe->lqe_qunit;
1185                                 /* qunit could be not set,
1186                                  * so use global lqe's qunit */
1187                                 if (!new_qunit)
1188                                         continue;
1189
1190                                 if (lge_qunit != new_qunit)
1191                                         lgd->lqeg_arr[idx].lge_qunit =
1192                                                                 new_qunit;
1193
1194                                 /* TODO: initially slaves notification was done
1195                                  * only for qunit shrinking. Should we always
1196                                  * notify slaves with new qunit ? */
1197                                 if (lge_qunit > new_qunit)
1198                                         lgd->lqeg_arr[idx].lge_qunit_nu = 1;
1199                                 lgd->lqeg_arr[idx].lge_qunit_set = 1;
1200                         }
1201                 }
1202
1203                 if (!qmt_pool_global(qpi))
1204                         up_read(sem);
1205         }
1206         /* TODO: only for debug purposes - remove it later */
1207         for (i = 0; i < lgd->lqeg_num_used; i++)
1208                 CDEBUG(D_QUOTA,
1209                         "lgd ost %d, qunit %lu nu %d;  edquot %d nu %d\n",
1210                         i, (long unsigned)lgd->lqeg_arr[i].lge_qunit,
1211                         lgd->lqeg_arr[i].lge_qunit_nu,
1212                         lgd->lqeg_arr[i].lge_edquot,
1213                         lgd->lqeg_arr[i].lge_edquot_nu);
1214
1215         EXIT;
1216 }
1217
1218 void qmt_setup_lqe_gd(const struct lu_env *env, struct qmt_device *qmt,
1219                       struct lquota_entry *lqe, struct lqe_glbl_data *lgd,
1220                       int pool_type)
1221 {
1222         __u64                    qunit;
1223         bool                     edquot;
1224         int                      i;
1225
1226         qunit = lqe->lqe_qunit;
1227         edquot = lqe->lqe_edquot;
1228
1229         /* Firstly set all elements in array with
1230          * qunit and edquot of global pool */
1231         for (i = 0; i < lgd->lqeg_num_used; i++) {
1232                 lgd->lqeg_arr[i].lge_qunit = qunit;
1233                 lgd->lqeg_arr[i].lge_edquot = edquot;
1234                 /* It is the very first lvb setup - qunit and other flags
1235                  * will be sent to slaves during qmt_lvbo_fill. */
1236                 lgd->lqeg_arr[i].lge_qunit_nu = 0;
1237                 lgd->lqeg_arr[i].lge_edquot_nu = 0;
1238         }
1239
1240         qmt_pool_lqes_lookup_spec(env, qmt, pool_type,
1241                                   lqe_qtype(lqe), &lqe->lqe_id);
1242         qmt_seed_glbe(env, lgd);
1243
1244         lqe->lqe_glbl_data = lgd;
1245         qmt_id_lock_notify(qmt, lqe);
1246
1247         qti_lqes_fini(env);
1248 }