使用go-ceph創(chuàng)建subvolume

背景介紹

需要訪問ceph創(chuàng)建subvolume卷,因為在ceph quincy版本rest api不支持subvolume的創(chuàng)建(reef版本已經(jīng)支持)。所以需要引入ceph的sdk庫進行subvlume的創(chuàng)建。我選擇的是go-ceph:github.com/ceph/go-ceph

前提條件

  1. 在ceph已創(chuàng)建好volume和subvolumegroup
ceph fs volume create xxx
ceph fs subvolumegroup create <vol_name> <group_name>
  1. 創(chuàng)建對接賬號
ceph auth get-or-create client.test mon "allow r" mds "allow rw" osd 'allow rwx pool=cephfs.testfs.data'
#生成密鑰對
ceph auth get client.test -o ceph.client.test.keyring
ceph auth print-key client.test> test.key

創(chuàng)建subvolume

創(chuàng)建go-ceph客戶端(參考csi代碼修改)

import (
    "fmt"
    "github.com/ceph/go-ceph/rados"
)
const (
    cephConfigRoot = "/etc/ceph"
    // CephConfigPath ceph configuration file.
    CephConfigPath = "/etc/ceph/ceph.conf"
    keyRing = "/etc/ceph/keyring"
)
func GetConn(monitors, user, keyfile string) (*rados.Conn, error) {
    // construct and connect a new rados.Conn
    args := []string{"--keyfile=" + keyfile}
    conn, err := rados.NewConnWithUser(user)
    if err != nil {
        return nil, fmt.Errorf("creating a new connection failed: %w", err)
    }
    err = conn.ParseCmdLineArgs(args)
    if err != nil {
        return nil, fmt.Errorf("parsing cmdline args (%v) failed: %w", args, err)
    }
    if err = conn.ReadConfigFile(CephConfigPath); err != nil {
        return nil, fmt.Errorf("failed to read config file %q: %w", CephConfigPath, err)
    }
    err = conn.Connect()
    if err != nil {
        return nil, fmt.Errorf("connecting failed: %w", err)
    }
    return conn, nil
}
conn, err := GetConn("", "slurm", "/etc/ceph/slurm.key")

創(chuàng)建ceph fs客戶端, 并創(chuàng)建subvolume

import ca "github.com/ceph/go-ceph/cephfs/admin"

fsadmin := ca.NewFromConn(conn)
if err := fsadmin.CreateSubVolume("testfs", "data", fmt.Sprintf("mount%d", rand.Intn(100)), &ca.SubVolumeOptions{Size: 10}); err != nil {
    fmt.Printf("create subvolume err, %v", err)
    eturn err
}
return nil

編譯

因為go-ceph 引入了ceph的c語言動態(tài)鏈接庫,需要找一臺linux機器,安裝對應(yīng)的動態(tài)鏈接庫之后才能正常編譯。ceph-go中已經(jīng)做了相關(guān)說明GitHub - ceph/go-ceph: Go bindings for Ceph :octopus: :octopus:

The code in go-ceph is purely a library module. Typically, one will import go-ceph in another Go based project. When building the code the native RADOS, RBD, & CephFS library and development headers are expected to be installed.
On debian based systems (apt) these may be:

libcephfs-dev librbd-dev librados-dev
On rpm based systems (dnf, yum, etc) these may be:

libcephfs-devel librbd-devel librados-devel
On MacOS you can use brew to install the libraries:

brew tap mulbc/ceph-client
brew install ceph-client

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容