Whamcloud - gitweb
LU-10973 lnet: infrastructure to build the LUTF
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_quota.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, 2017, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * Author: Johann Lombardi <johann@whamcloud.com>
28  * Author: Niu    Yawei    <niu@whamcloud.com>
29  */
30
31 #include <lustre_quota.h>
32 #include "osd_internal.h"
33
34 /**
35  * Helpers function to find out the quota type (USRQUOTA/GRPQUOTA) of a
36  * given object
37  */
38 static inline int fid2type(const struct lu_fid *fid)
39 {
40         LASSERT(fid_is_acct(fid));
41         switch (fid_oid(fid)) {
42         case ACCT_USER_OID:
43                 return USRQUOTA;
44         case ACCT_GROUP_OID:
45                 return GRPQUOTA;
46         case ACCT_PROJECT_OID:
47                 return PRJQUOTA;
48         }
49
50         LASSERTF(0, "invalid fid for quota type: %u\n", fid_oid(fid));
51         return USRQUOTA;
52 }
53
54 /**
55  * Space Accounting Management
56  */
57
58 /**
59  * Look up an accounting object based on its fid.
60  *
61  * \param info - is the osd thread info passed by the caller
62  * \param osd  - is the osd device
63  * \param fid  - is the fid of the accounting object we want to look up
64  * \param id   - is the osd_inode_id struct to fill with the inode number of
65  *               the quota file if the lookup is successful
66  */
67 int osd_acct_obj_lookup(struct osd_thread_info *info, struct osd_device *osd,
68                         const struct lu_fid *fid, struct osd_inode_id *id)
69 {
70         struct super_block *sb = osd_sb(osd);
71
72         ENTRY;
73         LASSERT(fid_is_acct(fid));
74
75         if (!ldiskfs_has_feature_quota(sb))
76                 RETURN(-ENOENT);
77
78         id->oii_gen = OSD_OII_NOGEN;
79         switch (fid2type(fid)) {
80         case USRQUOTA:
81                 id->oii_ino =
82                         le32_to_cpu(LDISKFS_SB(sb)->s_es->s_usr_quota_inum);
83                 break;
84         case GRPQUOTA:
85                 id->oii_ino =
86                         le32_to_cpu(LDISKFS_SB(sb)->s_es->s_grp_quota_inum);
87                 break;
88         case PRJQUOTA:
89 #ifdef HAVE_PROJECT_QUOTA
90                 if (ldiskfs_has_feature_project(sb)) {
91                         __le32 prj_quota;
92
93                         prj_quota = LDISKFS_SB(sb)->s_es->s_prj_quota_inum;
94                         id->oii_ino = le32_to_cpu(prj_quota);
95                 } else
96 #endif
97                         RETURN(-ENOENT);
98                 break;
99         }
100
101         if (!ldiskfs_valid_inum(sb, id->oii_ino) &&
102             id->oii_ino != LDISKFS_USR_QUOTA_INO &&
103             id->oii_ino != LDISKFS_GRP_QUOTA_INO)
104                 RETURN(-ENOENT);
105
106         RETURN(0);
107 }
108
109 /**
110  * Return space usage (#blocks & #inodes) consumed by a given uid or gid.
111  *
112  * \param env   - is the environment passed by the caller
113  * \param dtobj - is the accounting object
114  * \param dtrec - is the record to fill with space usage information
115  * \param dtkey - is the id of the user or group for which we would
116  *                like to access disk usage.
117  *
118  * \retval +ve - success : exact match
119  * \retval -ve - failure
120  */
121 static int osd_acct_index_lookup(const struct lu_env *env,
122                                  struct dt_object *dtobj,
123                                  struct dt_rec *dtrec,
124                                  const struct dt_key *dtkey)
125 {
126         struct osd_thread_info *info = osd_oti_get(env);
127 #if defined(HAVE_DQUOT_QC_DQBLK)
128         struct qc_dqblk *dqblk = &info->oti_qdq;
129 #else
130         struct fs_disk_quota *dqblk = &info->oti_fdq;
131 #endif
132         struct super_block *sb = osd_sb(osd_obj2dev(osd_dt_obj(dtobj)));
133         struct lquota_acct_rec *rec = (struct lquota_acct_rec *)dtrec;
134         __u64 id = *((__u64 *)dtkey);
135         int rc;
136         struct kqid qid;
137         int type;
138
139         ENTRY;
140
141         type = fid2type(lu_object_fid(&dtobj->do_lu));
142         memset(dqblk, 0, sizeof(*dqblk));
143         qid = make_kqid(&init_user_ns, type, id);
144         rc = sb->s_qcop->get_dqblk(sb, qid, dqblk);
145         if (rc)
146                 RETURN(rc);
147 #if defined(HAVE_DQUOT_QC_DQBLK)
148         rec->bspace = dqblk->d_space;
149         rec->ispace = dqblk->d_ino_count;
150 #else
151         rec->bspace = dqblk->d_bcount;
152         rec->ispace = dqblk->d_icount;
153 #endif
154         RETURN(+1);
155 }
156
157 #define QUOTA_IT_READ_ERROR(it, rc)                                    \
158         CERROR("%s: Error while trying to read quota information, "    \
159                "failed with %d\n",                                     \
160                osd_dev(it->oiq_obj->oo_dt.do_lu.lo_dev)->od_svname, rc) \
161
162 /**
163  * Initialize osd Iterator for given osd index object.
164  *
165  * \param  dt    - osd index object
166  * \param  attr  - not used
167  */
168 static struct dt_it *osd_it_acct_init(const struct lu_env *env,
169                                       struct dt_object *dt,
170                                       __u32 attr)
171 {
172         struct osd_it_quota *it;
173         struct lu_object *lo = &dt->do_lu;
174         struct osd_object *obj = osd_dt_obj(dt);
175
176         ENTRY;
177
178         LASSERT(lu_object_exists(lo));
179
180         OBD_ALLOC_PTR(it);
181         if (it == NULL)
182                 RETURN(ERR_PTR(-ENOMEM));
183
184         lu_object_get(lo);
185         it->oiq_obj = obj;
186         INIT_LIST_HEAD(&it->oiq_list);
187
188         /* LUSTRE_DQTREEOFF is the initial offset where the tree can be found */
189         it->oiq_blk[0] = LUSTRE_DQTREEOFF;
190
191         /*
192          * NB: we don't need to store the tree depth since it is always
193          * equal to LUSTRE_DQTREEDEPTH - 1 (root has depth = 0) for a leaf
194          * block.
195          */
196         RETURN((struct dt_it *)it);
197 }
198
199 /**
200  * Free given iterator.
201  *
202  * \param  di   - osd iterator
203  */
204 static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
205 {
206         struct osd_it_quota *it = (struct osd_it_quota *)di;
207         struct osd_quota_leaf *leaf, *tmp;
208
209         ENTRY;
210
211         osd_object_put(env, it->oiq_obj);
212
213         list_for_each_entry_safe(leaf, tmp, &it->oiq_list, oql_link) {
214                 list_del_init(&leaf->oql_link);
215                 OBD_FREE_PTR(leaf);
216         }
217
218         OBD_FREE_PTR(it);
219
220         EXIT;
221 }
222
223 /**
224  * Move Iterator to record specified by \a key, if the \a key isn't found,
225  * move to the first valid record.
226  *
227  * \param  di   - osd iterator
228  * \param  key  - uid or gid
229  *
230  * \retval +ve  - di points to the first valid record
231  * \retval  +1  - di points to exact matched key
232  * \retval -ve  - failure
233  */
234 static int osd_it_acct_get(const struct lu_env *env, struct dt_it *di,
235                            const struct dt_key *key)
236 {
237         struct osd_it_quota *it = (struct osd_it_quota *)di;
238         const struct lu_fid *fid = lu_object_fid(&it->oiq_obj->oo_dt.do_lu);
239         int type;
240         qid_t dqid = *(qid_t *)key;
241         loff_t offset;
242         int rc;
243
244         ENTRY;
245         type = fid2type(fid);
246
247         offset = find_tree_dqentry(env, it->oiq_obj, type, dqid,
248                                    LUSTRE_DQTREEOFF, 0, it);
249         if (offset > 0) { /* Found */
250                 RETURN(+1);
251         } else if (offset < 0) { /* Error */
252                 QUOTA_IT_READ_ERROR(it, (int)offset);
253                 RETURN((int)offset);
254         }
255
256         /* The @key is not found, move to the first valid entry */
257         rc = walk_tree_dqentry(env, it->oiq_obj, type, it->oiq_blk[0], 0,
258                                0, it);
259         if (rc == 0)
260                 rc = 1;
261         else if (rc > 0)
262                 rc = -ENOENT;
263
264         RETURN(rc);
265 }
266
267 /**
268  * Release Iterator
269  *
270  * \param  di   - osd iterator
271  */
272 static void osd_it_acct_put(const struct lu_env *env, struct dt_it *di)
273 {
274         return;
275 }
276
277 static int osd_it_add_processed(struct osd_it_quota *it, int depth)
278 {
279         struct osd_quota_leaf *leaf;
280
281         OBD_ALLOC_PTR(leaf);
282         if (leaf == NULL)
283                 RETURN(-ENOMEM);
284         INIT_LIST_HEAD(&leaf->oql_link);
285         leaf->oql_blk = it->oiq_blk[depth];
286         list_add_tail(&leaf->oql_link, &it->oiq_list);
287         RETURN(0);
288 }
289
290 /**
291  * Move on to the next valid entry.
292  *
293  * \param  di   - osd iterator
294  *
295  * \retval +ve  - iterator reached the end
296  * \retval   0  - iterator has not reached the end yet
297  * \retval -ve  - unexpected failure
298  */
299 static int osd_it_acct_next(const struct lu_env *env, struct dt_it *di)
300 {
301         struct osd_it_quota *it = (struct osd_it_quota *)di;
302         const struct lu_fid *fid = lu_object_fid(&it->oiq_obj->oo_dt.do_lu);
303         int type;
304         int depth, rc;
305         uint index;
306
307         ENTRY;
308
309         type = fid2type(fid);
310
311         /*
312          * Let's first check if there are any remaining valid entry in the
313          * current leaf block. Start with the next entry after the current one.
314          */
315         depth = LUSTRE_DQTREEDEPTH;
316         index = it->oiq_index[depth];
317         if (++index < LUSTRE_DQSTRINBLK) {
318                 /* Search for the next valid entry from current index */
319                 rc = walk_block_dqentry(env, it->oiq_obj, type,
320                                         it->oiq_blk[depth], index, it);
321                 if (rc < 0) {
322                         QUOTA_IT_READ_ERROR(it, rc);
323                         RETURN(rc);
324                 } else if (rc == 0) {
325                         /*
326                          * Found on entry, @it is already updated to the
327                          * new position in walk_block_dqentry().
328                          */
329                         RETURN(0);
330                 } else {
331                         rc = osd_it_add_processed(it, depth);
332                         if (rc)
333                                 RETURN(rc);
334                 }
335         } else {
336                 rc = osd_it_add_processed(it, depth);
337                 if (rc)
338                         RETURN(rc);
339         }
340         rc = 1;
341
342         /*
343          * We have consumed all the entries of the current leaf block, move on
344          * to the next one.
345          */
346         depth--;
347
348         /*
349          * We keep searching as long as walk_tree_dqentry() returns +1
350          * (= no valid entry found).
351          */
352         for (; depth >= 0 && rc > 0; depth--) {
353                 index = it->oiq_index[depth];
354                 if (++index > 0xff)
355                         continue;
356                 rc = walk_tree_dqentry(env, it->oiq_obj, type,
357                                        it->oiq_blk[depth], depth, index, it);
358         }
359
360         if (rc < 0)
361                 QUOTA_IT_READ_ERROR(it, rc);
362         RETURN(rc);
363 }
364
365 /**
366  * Return pointer to the key under iterator.
367  *
368  * \param  di   - osd iterator
369  */
370 static struct dt_key *osd_it_acct_key(const struct lu_env *env,
371                                       const struct dt_it *di)
372 {
373         struct osd_it_quota *it = (struct osd_it_quota *)di;
374
375         ENTRY;
376         RETURN((struct dt_key *)&it->oiq_id);
377 }
378
379 /**
380  * Return size of key under iterator (in bytes)
381  *
382  * \param  di   - osd iterator
383  */
384 static int osd_it_acct_key_size(const struct lu_env *env,
385                                 const struct dt_it *di)
386 {
387         struct osd_it_quota *it = (struct osd_it_quota *)di;
388
389         ENTRY;
390         RETURN((int)sizeof(it->oiq_id));
391 }
392
393 /**
394  * Return pointer to the record under iterator.
395  *
396  * \param  di    - osd iterator
397  * \param  attr  - not used
398  */
399 static int osd_it_acct_rec(const struct lu_env *env,
400                            const struct dt_it *di,
401                            struct dt_rec *dtrec, __u32 attr)
402 {
403         struct osd_it_quota *it = (struct osd_it_quota *)di;
404         const struct dt_key *key = osd_it_acct_key(env, di);
405         int rc;
406
407         ENTRY;
408
409         rc = osd_acct_index_lookup(env, &it->oiq_obj->oo_dt, dtrec, key);
410         RETURN(rc > 0 ? 0 : rc);
411 }
412
413 /**
414  * Returns cookie for current Iterator position.
415  *
416  * \param  di    - osd iterator
417  */
418 static __u64 osd_it_acct_store(const struct lu_env *env,
419                                const struct dt_it *di)
420 {
421         struct osd_it_quota *it = (struct osd_it_quota *)di;
422
423         ENTRY;
424         RETURN(it->oiq_id);
425 }
426
427 /**
428  * Restore iterator from cookie. if the \a hash isn't found,
429  * restore the first valid record.
430  *
431  * \param  di    - osd iterator
432  * \param  hash  - iterator location cookie
433  *
434  * \retval +ve   - di points to the first valid record
435  * \retval  +1   - di points to exact matched hash
436  * \retval -ve   - failure
437  */
438 static int osd_it_acct_load(const struct lu_env *env,
439                             const struct dt_it *di, __u64 hash)
440 {
441         struct osd_it_quota *it = (struct osd_it_quota *)di;
442
443         ENTRY;
444
445         /*
446          * LU-8999 - If it is called to resume the iteration, calling
447          * osd_it_acct_get could change the block orders in the lower level
448          * of the quota tree, which are saved in osd_it_quota->oiq_blk.
449          */
450         if (it->oiq_id != 0 && it->oiq_id == hash)
451                 RETURN(1);
452
453         RETURN(osd_it_acct_get(env, (struct dt_it *)di,
454                                (const struct dt_key *)&hash));
455 }
456
457 /**
458  * Index and Iterator operations for accounting objects
459  */
460 const struct dt_index_operations osd_acct_index_ops = {
461         .dio_lookup = osd_acct_index_lookup,
462         .dio_it = {
463                 .init           = osd_it_acct_init,
464                 .fini           = osd_it_acct_fini,
465                 .get            = osd_it_acct_get,
466                 .put            = osd_it_acct_put,
467                 .next           = osd_it_acct_next,
468                 .key            = osd_it_acct_key,
469                 .key_size       = osd_it_acct_key_size,
470                 .rec            = osd_it_acct_rec,
471                 .store          = osd_it_acct_store,
472                 .load           = osd_it_acct_load
473         }
474 };
475
476 static inline void osd_quota_swab(char *ptr, size_t size)
477 {
478         int offset;
479
480         LASSERT((size & (sizeof(__u64) - 1)) == 0);
481
482         for (offset = 0; offset < size; offset += sizeof(__u64))
483                 __swab64s((__u64 *)(ptr + offset));
484 }
485
486 const struct dt_rec *osd_quota_pack(struct osd_object *obj,
487                                     const struct dt_rec *rec,
488                                     union lquota_rec *quota_rec)
489 {
490 #ifdef __BIG_ENDIAN
491         struct iam_descr        *descr;
492
493         LASSERT(obj->oo_dir != NULL);
494         descr = obj->oo_dir->od_container.ic_descr;
495
496         memcpy(quota_rec, rec, descr->id_rec_size);
497
498         osd_quota_swab((char *)quota_rec, descr->id_rec_size);
499         return (const struct dt_rec *)quota_rec;
500 #else
501         return rec;
502 #endif
503 }
504
505 void osd_quota_unpack(struct osd_object *obj, const struct dt_rec *rec)
506 {
507 #ifdef __BIG_ENDIAN
508         struct iam_descr *descr;
509
510         LASSERT(obj->oo_dir != NULL);
511         descr = obj->oo_dir->od_container.ic_descr;
512
513         osd_quota_swab((char *)rec, descr->id_rec_size);
514 #endif
515 }
516
517 static inline int osd_qid_type(struct osd_thandle *oh, int i)
518 {
519         return oh->ot_id_types[i];
520 }
521
522 /**
523  * Reserve journal credits for quota files update first, then call
524  * ->op_begin() to perform quota enforcement.
525  *
526  * \param  env     - the environment passed by the caller
527  * \param  oh      - osd transaction handle
528  * \param  qi      - quota id & space required for this operation
529  * \param  obj     - osd object, could be NULL when it's under create
530  * \param  enforce - whether to perform quota enforcement
531  * \param  flags   - if the operation is write, return no user quota, no
532  *                   group quota, or sync commit flags to the caller
533  *
534  * \retval 0       - success
535  * \retval -ve     - failure
536  */
537 int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
538                     struct lquota_id_info *qi, struct osd_object *obj,
539                     bool enforce, enum osd_quota_local_flags *local_flags)
540 {
541         struct osd_device *dev;
542         struct qsd_instance *qsd;
543         struct inode *inode = NULL;
544         int i, rc = 0, crd;
545         __u8 res = qi->lqi_is_blk ? LQUOTA_RES_DT : LQUOTA_RES_MD;
546         bool found = false;
547
548         ENTRY;
549
550         LASSERT(oh != NULL);
551         LASSERTF(oh->ot_id_cnt <= OSD_MAX_UGID_CNT, "count=%d\n",
552                  oh->ot_id_cnt);
553
554         dev = osd_dt_dev(oh->ot_super.th_dev);
555         LASSERT(dev != NULL);
556
557         if (res == LQUOTA_RES_DT)
558                 qsd = dev->od_quota_slave_dt;
559         else
560                 qsd = dev->od_quota_slave_md;
561
562         for (i = 0; i < oh->ot_id_cnt; i++) {
563                 if (oh->ot_id_array[i] == qi->lqi_id.qid_uid &&
564                     oh->ot_id_res[i] == res &&
565                     oh->ot_id_types[i] == qi->lqi_type) {
566                         found = true;
567                         break;
568                 }
569         }
570
571         if (!found) {
572                 /* we need to account for credits for this new ID */
573                 if (i >= OSD_MAX_UGID_CNT) {
574                         CERROR("Too many(%d) trans qids!\n", i + 1);
575                         RETURN(-EOVERFLOW);
576                 }
577
578                 if (obj != NULL)
579                         inode = obj->oo_inode;
580
581                 if (qi->lqi_id.qid_uid == 0) {
582                         /* root ID should be always present in the quota file */
583                         crd = 1;
584                 } else {
585                         /* can't rely on the current state as it can change
586                          * by the execution.
587                          * if used space for this ID could be dropped to zero,
588                          * reserve extra credits for removing ID entry from
589                          * the quota file
590                          */
591                         if (qi->lqi_space < 0)
592                                 crd = LDISKFS_QUOTA_DEL_BLOCKS(osd_sb(dev));
593                         else
594                                 crd = LDISKFS_QUOTA_INIT_BLOCKS(osd_sb(dev));
595                 }
596
597                 osd_trans_declare_op(env, oh, OSD_OT_QUOTA, crd);
598
599                 oh->ot_id_array[i] = qi->lqi_id.qid_uid;
600                 oh->ot_id_types[i] = qi->lqi_type;
601                 oh->ot_id_res[i] = res;
602                 oh->ot_id_cnt++;
603         }
604
605         if (unlikely(qsd == NULL))
606                 /* quota slave instance hasn't been allocated yet */
607                 RETURN(0);
608
609         /* check quota */
610         if (enforce)
611                 rc = qsd_op_begin(env, qsd, oh->ot_quota_trans, qi,
612                                   local_flags);
613         RETURN(rc);
614 }
615
616 /**
617  * Wrapper for osd_declare_qid()
618  *
619  * \param  env    - the environment passed by the caller
620  * \param  uid    - user id of the inode
621  * \param  gid    - group id of the inode
622  * \param  space  - how many blocks/inodes will be consumed/released
623  * \param  oh     - osd transaction handle
624  * \param  obj    - osd object, could be NULL when it's under create
625  * \param  flags  - if the operation is write, return no user quota, no
626  *                  group quota, or sync commit flags to the caller
627  * \param osd_qid_flags - indicate this is a inode/block accounting
628  *                      and whether changes are performed by root user
629  *
630  * \retval 0      - success
631  * \retval -ve    - failure
632  */
633 int osd_declare_inode_qid(const struct lu_env *env, qid_t uid, qid_t gid,
634                           __u32 projid, long long space, struct osd_thandle *oh,
635                           struct osd_object *obj,
636                           enum osd_quota_local_flags *local_flags,
637                           enum osd_qid_declare_flags osd_qid_declare_flags)
638 {
639         struct osd_thread_info *info = osd_oti_get(env);
640         struct lquota_id_info *qi = &info->oti_qi;
641         int rcu, rcg, rcp = 0; /* user & group & project rc */
642         struct thandle *th = &oh->ot_super;
643         bool force = !!(osd_qid_declare_flags & OSD_QID_FORCE) ||
644                         th->th_ignore_quota;
645         ENTRY;
646
647         /* let's start with user quota */
648         qi->lqi_id.qid_uid = uid;
649         qi->lqi_type = USRQUOTA;
650         qi->lqi_space = space;
651         qi->lqi_is_blk = !!(osd_qid_declare_flags & OSD_QID_BLK);
652         rcu = osd_declare_qid(env, oh, qi, obj, true, local_flags);
653
654         if (force && (rcu == -EDQUOT || rcu == -EINPROGRESS))
655                 /* ignore EDQUOT & EINPROGRESS when changes are done by root */
656                 rcu = 0;
657
658         /*
659          * For non-fatal error, we want to continue to get the noquota flags
660          * for group id. This is only for commit write, which has @flags passed
661          * in. See osd_declare_write_commit().
662          * When force is set to true, we also want to proceed with the gid
663          */
664         if (rcu && (rcu != -EDQUOT || local_flags == NULL))
665                 RETURN(rcu);
666
667         /* and now group quota */
668         qi->lqi_id.qid_gid = gid;
669         qi->lqi_type = GRPQUOTA;
670         rcg = osd_declare_qid(env, oh, qi, obj, true, local_flags);
671
672         if (force && (rcg == -EDQUOT || rcg == -EINPROGRESS))
673                 /* as before, ignore EDQUOT & EINPROGRESS for root */
674                 rcg = 0;
675
676 #ifdef HAVE_PROJECT_QUOTA
677         if (rcg && (rcg != -EDQUOT || local_flags == NULL))
678                 RETURN(rcg);
679
680         /* and now project quota */
681         qi->lqi_id.qid_projid = projid;
682         qi->lqi_type = PRJQUOTA;
683         rcp = osd_declare_qid(env, oh, qi, obj, true, local_flags);
684
685         if (force && (rcp == -EDQUOT || rcp == -EINPROGRESS)) {
686                 CDEBUG(D_QUOTA, "forced to ignore quota flags = %#x\n",
687                        local_flags ? *local_flags : -1);
688                 /* as before, ignore EDQUOT & EINPROGRESS for root */
689                 rcp = 0;
690         }
691 #endif
692
693         RETURN(rcu ? rcu : (rcg ? rcg : rcp));
694 }