Whamcloud - gitweb
30fb5b42ac6561f8cda15079709de9d87ad0dac0
[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
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 ost_lvb *lvb, __u64 *kms_place)
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         s64 current_mtime = lvb->lvb_mtime;
52         s64 current_atime = lvb->lvb_atime;
53         s64 current_ctime = lvb->lvb_ctime;
54         int i;
55         int rc = 0;
56
57         assert_spin_locked(&lsm->lsm_lock);
58         LASSERT(lsm->lsm_lock_owner == current->pid);
59
60         CDEBUG(D_INODE, "MDT ID "DOSTID" initial value: s=%llu m=%llu"
61                " a=%llu c=%llu b=%llu\n", POSTID(&lsm->lsm_oi),
62                lvb->lvb_size, lvb->lvb_mtime, lvb->lvb_atime, lvb->lvb_ctime,
63                lvb->lvb_blocks);
64         for (i = 0; i < lse->lsme_stripe_count; i++) {
65                 struct lov_oinfo *loi = lse->lsme_oinfo[i];
66                 u64 lov_size;
67                 u64 tmpsize;
68
69                 if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
70                         rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
71                         continue;
72                 }
73
74                 tmpsize = loi->loi_kms;
75                 lov_size = lov_stripe_size(lsm, index, tmpsize, i);
76                 if (lov_size > kms)
77                         kms = lov_size;
78
79                 if (loi->loi_lvb.lvb_size > tmpsize)
80                         tmpsize = loi->loi_lvb.lvb_size;
81
82                 lov_size = lov_stripe_size(lsm, index, tmpsize, i);
83                 if (lov_size > size)
84                         size = lov_size;
85                 /* merge blocks, mtime, atime */
86                 blocks += loi->loi_lvb.lvb_blocks;
87                 if (loi->loi_lvb.lvb_mtime > current_mtime)
88                         current_mtime = loi->loi_lvb.lvb_mtime;
89                 if (loi->loi_lvb.lvb_atime > current_atime)
90                         current_atime = loi->loi_lvb.lvb_atime;
91                 if (loi->loi_lvb.lvb_ctime > current_ctime)
92                         current_ctime = loi->loi_lvb.lvb_ctime;
93
94                 CDEBUG(D_INODE, "MDT ID "DOSTID" on OST[%u]: s=%llu m=%llu"
95                        " a=%llu c=%llu b=%llu\n", POSTID(&lsm->lsm_oi),
96                        loi->loi_ost_idx, loi->loi_lvb.lvb_size,
97                        loi->loi_lvb.lvb_mtime, loi->loi_lvb.lvb_atime,
98                        loi->loi_lvb.lvb_ctime, loi->loi_lvb.lvb_blocks);
99         }
100
101         *kms_place = kms;
102         lvb->lvb_size = size;
103         lvb->lvb_blocks = blocks;
104         lvb->lvb_mtime = current_mtime;
105         lvb->lvb_atime = current_atime;
106         lvb->lvb_ctime = current_ctime;
107         RETURN(rc);
108 }