tfsDisk.c 1.5 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
Shengliang Guan 已提交
16
#define _DEFAULT_SOURCE
S
Shengliang Guan 已提交
17
#include "tfsInt.h"
H
Hongze Cheng 已提交
18

19
SDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) {
S
Shengliang Guan 已提交
20
  SDisk *pDisk = calloc(1, sizeof(SDisk));
H
Hongze Cheng 已提交
21
  if (pDisk == NULL) {
S
Shengliang Guan 已提交
22
    terrno = TSDB_CODE_OUT_OF_MEMORY;
H
Hongze Cheng 已提交
23 24 25
    return NULL;
  }

26 27 28 29 30 31 32
  pDisk->path = strdup(path);
  if (pDisk->path == NULL) {
    free(pDisk);
    terrno = TSDB_CODE_OUT_OF_MEMORY;
    return NULL;
  }

H
Hongze Cheng 已提交
33 34
  pDisk->level = level;
  pDisk->id = id;
35
  taosGetDiskSize(pDisk->path, &pDisk->size);
H
Hongze Cheng 已提交
36 37 38
  return pDisk;
}

H
Hongze Cheng 已提交
39
SDisk *tfsFreeDisk(SDisk *pDisk) {
S
Shengliang Guan 已提交
40
  if (pDisk != NULL) {
41
    free(pDisk->path);
H
Hongze Cheng 已提交
42
    free(pDisk);
H
Hongze Cheng 已提交
43
  }
S
Shengliang Guan 已提交
44

H
Hongze Cheng 已提交
45
  return NULL;
H
Hongze Cheng 已提交
46 47
}

48 49
int32_t tfsUpdateDiskSize(SDisk *pDisk) {
  if (taosGetDiskSize(pDisk->path, &pDisk->size) != 0) {
S
Shengliang Guan 已提交
50
    terrno = TAOS_SYSTEM_ERROR(errno);
51 52
    fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id, terrstr());
    return -1;
H
Hongze Cheng 已提交
53
  }
S
TD-1207  
Shengliang Guan 已提交
54

S
Shengliang Guan 已提交
55
  return 0;
56
}