4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LOV
40 #include <libcfs/libcfs.h>
42 #include <liblustre.h>
45 #include <obd_class.h>
48 #include "lov_internal.h"
50 /** Merge the lock value block(&lvb) attributes and KMS from each of the
51 * stripes in a file into a single lvb. It is expected that the caller
52 * initializes the current atime, mtime, ctime to avoid regressing a more
53 * uptodate time on the local client.
55 int lov_merge_lvb_kms(struct lov_stripe_md *lsm,
56 struct ost_lvb *lvb, __u64 *kms_place)
61 obd_time current_mtime = lvb->lvb_mtime;
62 obd_time current_atime = lvb->lvb_atime;
63 obd_time current_ctime = lvb->lvb_ctime;
66 struct lu_fid fid = {0};
68 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
70 LASSERT(lsm->lsm_lock_owner == cfs_curproc_pid());
73 ostid_to_fid(&fid, &lsm->lsm_oi, 0);
74 CDEBUG(D_INODE, "MDT FID "DFID" initial value: s="LPU64" m="LPU64
75 " a="LPU64" c="LPU64" b="LPU64"\n", PFID(&fid), lvb->lvb_size,
76 lvb->lvb_mtime, lvb->lvb_atime, lvb->lvb_ctime, lvb->lvb_blocks);
77 for (i = 0; i < lsm->lsm_stripe_count; i++) {
78 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
79 obd_size lov_size, tmpsize;
81 if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
82 rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
86 tmpsize = loi->loi_kms;
87 lov_size = lov_stripe_size(lsm, tmpsize, i);
91 if (loi->loi_lvb.lvb_size > tmpsize)
92 tmpsize = loi->loi_lvb.lvb_size;
94 lov_size = lov_stripe_size(lsm, tmpsize, i);
97 /* merge blocks, mtime, atime */
98 blocks += loi->loi_lvb.lvb_blocks;
99 if (loi->loi_lvb.lvb_mtime > current_mtime)
100 current_mtime = loi->loi_lvb.lvb_mtime;
101 if (loi->loi_lvb.lvb_atime > current_atime)
102 current_atime = loi->loi_lvb.lvb_atime;
103 if (loi->loi_lvb.lvb_ctime > current_ctime)
104 current_ctime = loi->loi_lvb.lvb_ctime;
106 CDEBUG(D_INODE, "MDT FID "DFID" on OST[%u]: s="LPU64" m="LPU64
107 " a="LPU64" c="LPU64" b="LPU64"\n", PFID(&fid),
108 loi->loi_ost_idx, loi->loi_lvb.lvb_size,
109 loi->loi_lvb.lvb_mtime, loi->loi_lvb.lvb_atime,
110 loi->loi_lvb.lvb_ctime, loi->loi_lvb.lvb_blocks);
114 lvb->lvb_size = size;
115 lvb->lvb_blocks = blocks;
116 lvb->lvb_mtime = current_mtime;
117 lvb->lvb_atime = current_atime;
118 lvb->lvb_ctime = current_ctime;
122 /** Merge the lock value block(&lvb) attributes from each of the stripes in a
123 * file into a single lvb. It is expected that the caller initializes the
124 * current atime, mtime, ctime to avoid regressing a more uptodate time on
127 * If \a kms_only is set then we do not consider the recently seen size (rss)
128 * when updating the known minimum size (kms). Even when merging RSS, we will
129 * take the KMS value if it's larger. This prevents getattr from stomping on
130 * dirty cached pages which extend the file size. */
131 int lov_merge_lvb(struct obd_export *exp,
132 struct lov_stripe_md *lsm, struct ost_lvb *lvb, int kms_only)
134 struct lu_fid fid = {0};
139 lov_stripe_lock(lsm);
140 rc = lov_merge_lvb_kms(lsm, lvb, &kms);
141 lov_stripe_unlock(lsm);
145 ostid_to_fid(&fid, &lsm->lsm_oi, 0);
146 CDEBUG(D_INODE, "merged for FID "DFID" s="LPU64" m="LPU64" a="LPU64
147 " c="LPU64" b="LPU64"\n", PFID(&fid), lvb->lvb_size,
148 lvb->lvb_mtime, lvb->lvb_atime, lvb->lvb_ctime, lvb->lvb_blocks);
152 /* Must be called under the lov_stripe_lock() */
153 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
154 obd_off size, int shrink)
156 struct lov_oinfo *loi;
161 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
163 LASSERT(lsm->lsm_lock_owner == cfs_curproc_pid());
167 for (; stripe < lsm->lsm_stripe_count; stripe++) {
168 struct lov_oinfo *loi = lsm->lsm_oinfo[stripe];
169 kms = lov_size_to_stripe(lsm, size, stripe);
171 "stripe %d KMS %sing "LPU64"->"LPU64"\n",
172 stripe, kms > loi->loi_kms ? "increas":"shrink",
174 loi_kms_set(loi, loi->loi_lvb.lvb_size = kms);
180 stripe = lov_stripe_number(lsm, size - 1);
181 kms = lov_size_to_stripe(lsm, size, stripe);
182 loi = lsm->lsm_oinfo[stripe];
184 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
185 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
186 if (kms > loi->loi_kms)
187 loi_kms_set(loi, kms);
192 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_valid valid,
193 struct lov_stripe_md *lsm, int stripeno, int *set)
195 valid &= src->o_valid;
198 if (valid & OBD_MD_FLSIZE) {
199 /* this handles sparse files properly */
202 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
203 if (lov_size > tgt->o_size)
204 tgt->o_size = lov_size;
206 if (valid & OBD_MD_FLBLOCKS)
207 tgt->o_blocks += src->o_blocks;
208 if (valid & OBD_MD_FLBLKSZ)
209 tgt->o_blksize += src->o_blksize;
210 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
211 tgt->o_ctime = src->o_ctime;
212 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
213 tgt->o_mtime = src->o_mtime;
214 if (valid & OBD_MD_FLDATAVERSION)
215 tgt->o_data_version += src->o_data_version;
217 memcpy(tgt, src, sizeof(*tgt));
218 tgt->o_oi = lsm->lsm_oi;
219 if (valid & OBD_MD_FLSIZE)
220 tgt->o_size = lov_stripe_size(lsm, src->o_size,
224 /* data_version needs to be valid on all stripes to be correct! */
225 if (!(valid & OBD_MD_FLDATAVERSION))
226 tgt->o_valid &= ~OBD_MD_FLDATAVERSION;