|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 NetEase Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/* |
| 18 | + * @Project: curve |
| 19 | + * @Date: 2021-06-04 14:11:16 |
| 20 | + * @Author: chenwei |
| 21 | + */ |
| 22 | + |
| 23 | +#include "curvefs/src/mds/fs.h" |
| 24 | +namespace curvefs { |
| 25 | +namespace mds { |
| 26 | +MdsFsInfo::MdsFsInfo(uint32_t fsId, std::string fsName, uint64_t rootInodeId, |
| 27 | + uint64_t capacity, uint64_t blockSize, const common::Volume& volume) { |
| 28 | + fsId_ = fsId; |
| 29 | + fsName_ = fsName; |
| 30 | + rootInodeId_ = rootInodeId; |
| 31 | + capacity_ = capacity; |
| 32 | + blockSize_ = blockSize; |
| 33 | + volume_.CopyFrom(volume); |
| 34 | + mountNum_ = 0; |
| 35 | +} |
| 36 | + |
| 37 | +void MdsFsInfo::ConvertToProto(FsInfo *file) { |
| 38 | + // ReadLockGuard readLockGuard(rwLock_); |
| 39 | + file->set_fsid(fsId_); |
| 40 | + file->set_fsname(fsName_); |
| 41 | + file->set_rootinodeid(rootInodeId_); |
| 42 | + file->set_capacity(capacity_); |
| 43 | + file->set_blocksize(blockSize_); |
| 44 | + file->set_mountnum(mountNum_); |
| 45 | + file->mutable_volume()->CopyFrom(volume_); |
| 46 | + *file->mutable_mountpoints() = {mountPointList_.begin(), |
| 47 | + mountPointList_.end()}; |
| 48 | + return; |
| 49 | +} |
| 50 | + |
| 51 | +std::list<MountPoint> MdsFsInfo::GetMountPointList() { |
| 52 | + return mountPointList_; |
| 53 | +} |
| 54 | + |
| 55 | +bool MdsFsInfo::MountPointEmpty() { |
| 56 | + return mountNum_ == 0; |
| 57 | +} |
| 58 | + |
| 59 | +bool MdsFsInfo::MountPointExist(const MountPoint& mountpoint) { |
| 60 | + // ReadLockGuard readLockGuard(rwLock_); |
| 61 | + for (auto it : mountPointList_) { |
| 62 | + if (it.host() == mountpoint.host() |
| 63 | + && it.mountdir() == mountpoint.mountdir()) { |
| 64 | + return true; |
| 65 | + } |
| 66 | + } |
| 67 | + return false; |
| 68 | +} |
| 69 | + |
| 70 | +void MdsFsInfo::AddMountPoint(const MountPoint& mountpoint) { |
| 71 | + // WriteLockGuard writeLockGuard(rwLock_); |
| 72 | + mountPointList_.push_back(mountpoint); |
| 73 | + mountNum_++; |
| 74 | + return; |
| 75 | +} |
| 76 | + |
| 77 | +FSStatusCode MdsFsInfo::DeleteMountPoint(const MountPoint& mountpoint) { |
| 78 | + // WriteLockGuard writeLockGuard(rwLock_); |
| 79 | + for (auto it = mountPointList_.begin(); it != mountPointList_.end(); it++) { |
| 80 | + if (it->host() == mountpoint.host() |
| 81 | + && it->mountdir() == mountpoint.mountdir()) { |
| 82 | + mountPointList_.erase(it); |
| 83 | + mountNum_--; |
| 84 | + return FSStatusCode::OK; |
| 85 | + } |
| 86 | + } |
| 87 | + return FSStatusCode::NOT_FOUND; |
| 88 | +} |
| 89 | + |
| 90 | +uint32_t MdsFsInfo::GetFsId() const { |
| 91 | + return fsId_; |
| 92 | +} |
| 93 | + |
| 94 | +std::string MdsFsInfo::GetFsName() const { |
| 95 | + return fsName_; |
| 96 | +} |
| 97 | + |
| 98 | +Volume MdsFsInfo::GetVolumeInfo() { |
| 99 | + return volume_; |
| 100 | +} |
| 101 | +} // namespace mds |
| 102 | +} // namespace curvefs |
0 commit comments