linux/drivers/staging/lustre/lustre/lov/lov_merge.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 * GPL HEADER START
   4 *
   5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6 *
   7 * This program is free software; you can redistribute it and/or modify
   8 * it under the terms of the GNU General Public License version 2 only,
   9 * as published by the Free Software Foundation.
  10 *
  11 * This program is distributed in the hope that it will be useful, but
  12 * WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14 * General Public License version 2 for more details (a copy is included
  15 * in the LICENSE file that accompanied this code).
  16 *
  17 * You should have received a copy of the GNU General Public License
  18 * version 2 along with this program; If not, see
  19 * http://www.gnu.org/licenses/gpl-2.0.html
  20 *
  21 * GPL HEADER END
  22 */
  23/*
  24 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  25 * Use is subject to license terms.
  26 *
  27 * Copyright (c) 2012, 2015, Intel Corporation.
  28 */
  29/*
  30 * This file is part of Lustre, http://www.lustre.org/
  31 * Lustre is a trademark of Sun Microsystems, Inc.
  32 */
  33
  34#define DEBUG_SUBSYSTEM S_LOV
  35
  36#include <linux/libcfs/libcfs.h>
  37
  38#include <obd_class.h>
  39#include "lov_internal.h"
  40
  41/** Merge the lock value block(&lvb) attributes and KMS from each of the
  42 * stripes in a file into a single lvb. It is expected that the caller
  43 * initializes the current atime, mtime, ctime to avoid regressing a more
  44 * uptodate time on the local client.
  45 */
  46int lov_merge_lvb_kms(struct lov_stripe_md *lsm,
  47                      struct ost_lvb *lvb, __u64 *kms_place)
  48{
  49        __u64 size = 0;
  50        __u64 kms = 0;
  51        __u64 blocks = 0;
  52        s64 current_mtime = lvb->lvb_mtime;
  53        s64 current_atime = lvb->lvb_atime;
  54        s64 current_ctime = lvb->lvb_ctime;
  55        int i;
  56        int rc = 0;
  57
  58        assert_spin_locked(&lsm->lsm_lock);
  59        LASSERT(lsm->lsm_lock_owner == current_pid());
  60
  61        CDEBUG(D_INODE, "MDT ID " DOSTID " initial value: s=%llu m=%llu a=%llu c=%llu b=%llu\n",
  62               POSTID(&lsm->lsm_oi), lvb->lvb_size, lvb->lvb_mtime,
  63               lvb->lvb_atime, lvb->lvb_ctime, lvb->lvb_blocks);
  64        for (i = 0; i < lsm->lsm_stripe_count; i++) {
  65                struct lov_oinfo *loi = lsm->lsm_oinfo[i];
  66                u64 lov_size, tmpsize;
  67
  68                if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
  69                        rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
  70                        continue;
  71                }
  72
  73                tmpsize = loi->loi_kms;
  74                lov_size = lov_stripe_size(lsm, tmpsize, i);
  75                if (lov_size > kms)
  76                        kms = lov_size;
  77
  78                if (loi->loi_lvb.lvb_size > tmpsize)
  79                        tmpsize = loi->loi_lvb.lvb_size;
  80
  81                lov_size = lov_stripe_size(lsm, tmpsize, i);
  82                if (lov_size > size)
  83                        size = lov_size;
  84                /* merge blocks, mtime, atime */
  85                blocks += loi->loi_lvb.lvb_blocks;
  86                if (loi->loi_lvb.lvb_mtime > current_mtime)
  87                        current_mtime = loi->loi_lvb.lvb_mtime;
  88                if (loi->loi_lvb.lvb_atime > current_atime)
  89                        current_atime = loi->loi_lvb.lvb_atime;
  90                if (loi->loi_lvb.lvb_ctime > current_ctime)
  91                        current_ctime = loi->loi_lvb.lvb_ctime;
  92
  93                CDEBUG(D_INODE, "MDT ID " DOSTID " on OST[%u]: s=%llu m=%llu a=%llu c=%llu b=%llu\n",
  94                       POSTID(&lsm->lsm_oi), loi->loi_ost_idx,
  95                       loi->loi_lvb.lvb_size, loi->loi_lvb.lvb_mtime,
  96                       loi->loi_lvb.lvb_atime, loi->loi_lvb.lvb_ctime,
  97                       loi->loi_lvb.lvb_blocks);
  98        }
  99
 100        *kms_place = kms;
 101        lvb->lvb_size = size;
 102        lvb->lvb_blocks = blocks;
 103        lvb->lvb_mtime = current_mtime;
 104        lvb->lvb_atime = current_atime;
 105        lvb->lvb_ctime = current_ctime;
 106        return rc;
 107}
 108