Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / lov / lov_merge.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  */
13
14 #define DEBUG_SUBSYSTEM S_LOV
15
16 #include <libcfs/libcfs.h>
17 #include <cl_object.h>
18 #include <obd_class.h>
19 #include "lov_internal.h"
20
21 /** Merge the lock value block(&lvb) attributes and KMS from each of the
22  * stripes in a file into a single lvb. It is expected that the caller
23  * initializes the current atime, mtime, ctime to avoid regressing a more
24  * uptodate time on the local client.
25  */
26 int lov_merge_lvb_kms(struct lov_stripe_md *lsm, int index,
27                       struct cl_attr *attr)
28 {
29         struct lov_stripe_md_entry *lse = lsm->lsm_entries[index];
30         u64 size = 0;
31         u64 kms = 0;
32         u64 blocks = 0;
33         /* XXX: timestamps can be negative by sanity:test_39m,
34          * how can it be? */
35         s64 current_mtime = LLONG_MIN;
36         s64 current_atime = LLONG_MIN;
37         s64 current_ctime = LLONG_MIN;
38         int i;
39         int rc = 0;
40
41         assert_spin_locked(&lsm->lsm_lock);
42         LASSERT(lsm->lsm_lock_owner == current->pid);
43         for (i = 0; i < lse->lsme_stripe_count; i++) {
44                 struct lov_oinfo *loi = lse->lsme_oinfo[i];
45                 u64 lov_size;
46                 u64 tmpsize;
47
48                 if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
49                         rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
50                         continue;
51                 }
52
53                 if (loi->loi_kms_valid) {
54                         attr->cat_kms_valid = 1;
55                         tmpsize = loi->loi_kms;
56                 } else {
57                         tmpsize = 0;
58                 }
59                 lov_size = lov_stripe_size(lsm, index, tmpsize, i);
60                 if (lov_size > kms)
61                         kms = lov_size;
62
63                 if (loi->loi_lvb.lvb_size > tmpsize)
64                         tmpsize = loi->loi_lvb.lvb_size;
65
66                 lov_size = lov_stripe_size(lsm, index, tmpsize, i);
67                 if (lov_size > size)
68                         size = lov_size;
69                 /* merge blocks, mtime, atime */
70                 blocks += loi->loi_lvb.lvb_blocks;
71                 if (loi->loi_lvb.lvb_mtime > current_mtime)
72                         current_mtime = loi->loi_lvb.lvb_mtime;
73                 if (loi->loi_lvb.lvb_atime > current_atime)
74                         current_atime = loi->loi_lvb.lvb_atime;
75                 if (loi->loi_lvb.lvb_ctime > current_ctime)
76                         current_ctime = loi->loi_lvb.lvb_ctime;
77
78                 CDEBUG(D_INODE, "MDT ID "DOSTID" on OST[%u]: s=%llu (%d) m=%llu"
79                        " a=%llu c=%llu b=%llu\n", POSTID(&lsm->lsm_oi),
80                        loi->loi_ost_idx, loi->loi_lvb.lvb_size,
81                        loi->loi_kms_valid, loi->loi_lvb.lvb_mtime,
82                        loi->loi_lvb.lvb_atime, loi->loi_lvb.lvb_ctime,
83                        loi->loi_lvb.lvb_blocks);
84         }
85
86         if (!rc) {
87                 attr->cat_kms    = kms;
88                 attr->cat_size   = size;
89                 attr->cat_mtime  = current_mtime;
90                 attr->cat_atime  = current_atime;
91                 attr->cat_ctime  = current_ctime;
92                 attr->cat_blocks = blocks;
93         }
94         RETURN(rc);
95 }