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