Skip to content

Commit

Permalink
Code formatting changes
Browse files Browse the repository at this point in the history
Signed-off-by: koko2pp <[email protected]>
  • Loading branch information
koko2pp committed Nov 27, 2023
1 parent ebf4508 commit b0148e2
Show file tree
Hide file tree
Showing 13 changed files with 9,330 additions and 8,831 deletions.
111 changes: 57 additions & 54 deletions curvefs_python/cbd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,62 @@

#include "curvefs_python/curve_type.h"

namespace curve {
namespace client {

class FileClient;

} // namespace client
} // namespace curve

class CBDClient {
public:
CBDClient();
~CBDClient();

int Init(const char* configPath);
void UnInit();

int Open(const char* filename, UserInfo_t* userInfo);
int Close(int fd);

int Create(const char* filename, UserInfo_t* userInfo, size_t size);
int Create2(const CreateContext* context);
int Unlink(const char* filename, UserInfo_t* info);
int DeleteForce(const char* filename, UserInfo_t* info);
int Recover(const char* filename, UserInfo_t* info, uint64_t fileId);
int Rename(UserInfo_t* info, const char* oldpath, const char* newpath);
int Extend(const char* filename, UserInfo_t* info, uint64_t size);

// Synchronous read and write
int Read(int fd, char* buf, unsigned long offset,
unsigned long length); // NOLINT
int Write(int fd, const char* buf, unsigned long offset,
unsigned long length); // NOLINT

// Asynchronous read and write
int AioRead(int fd, AioContext* aioctx);
int AioWrite(int fd, AioContext* aioctx);

// Obtain basic information about the file
int StatFile(const char* filename, UserInfo_t* info, FileInfo_t* finfo);
int ChangeOwner(const char* filename, const char* owner, UserInfo_t* info);

DirInfos_t* OpenDir(const char* dirpath, UserInfo_t* userinfo);
int Listdir(DirInfos_t* dirinfo);
void CloseDir(DirInfos_t* dirinfo);
int Mkdir(const char* dirpath, UserInfo_t* info);
int Rmdir(const char* dirpath, UserInfo_t* info);

std::string GetClusterId();

std::vector<std::string> ListPoolset();

private:
std::unique_ptr<curve::client::FileClient> client_;
namespace curve
{
namespace client
{

class FileClient;

} // namespace client
} // namespace curve

class CBDClient
{
public:
CBDClient();
~CBDClient();

int Init(const char *configPath);
void UnInit();

int Open(const char *filename, UserInfo_t *userInfo);
int Close(int fd);

int Create(const char *filename, UserInfo_t *userInfo, size_t size);
int Create2(const CreateContext *context);
int Unlink(const char *filename, UserInfo_t *info);
int DeleteForce(const char *filename, UserInfo_t *info);
int Recover(const char *filename, UserInfo_t *info, uint64_t fileId);
int Rename(UserInfo_t *info, const char *oldpath, const char *newpath);
int Extend(const char *filename, UserInfo_t *info, uint64_t size);

// Synchronous read and write
int Read(int fd, char *buf, unsigned long offset,
unsigned long length); // NOLINT
int Write(int fd, const char *buf, unsigned long offset,
unsigned long length); // NOLINT

// Asynchronous read and write
int AioRead(int fd, AioContext *aioctx);
int AioWrite(int fd, AioContext *aioctx);

// Obtain basic information about the file
int StatFile(const char *filename, UserInfo_t *info, FileInfo_t *finfo);
int ChangeOwner(const char *filename, const char *owner, UserInfo_t *info);

DirInfos_t *OpenDir(const char *dirpath, UserInfo_t *userinfo);
int Listdir(DirInfos_t *dirinfo);
void CloseDir(DirInfos_t *dirinfo);
int Mkdir(const char *dirpath, UserInfo_t *info);
int Rmdir(const char *dirpath, UserInfo_t *info);

std::string GetClusterId();

std::vector<std::string> ListPoolset();

private:
std::unique_ptr<curve::client::FileClient> client_;
};

#endif // CURVEFS_PYTHON_CBD_CLIENT_H_
#endif // CURVEFS_PYTHON_CBD_CLIENT_H_
65 changes: 33 additions & 32 deletions curvefs_python/libcurvefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* File Created: Tuesday, 25th September 2018 2:07:05 pm
* Author:
*/
#ifndef CURVE_LIBCURVE_INTERFACE_H // NOLINT
#ifndef CURVE_LIBCURVE_INTERFACE_H // NOLINT
#define CURVE_LIBCURVE_INTERFACE_H

#include <stdint.h>
Expand All @@ -31,47 +31,48 @@
#include "curvefs_python/curve_type.h"

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

int Init(const char* path);
int Open4Qemu(const char* filename);
int Open(const char* filename, UserInfo_t* info);
int Create(const char* filename, UserInfo_t* info, size_t size);
int Init(const char *path);
int Open4Qemu(const char *filename);
int Open(const char *filename, UserInfo_t *info);
int Create(const char *filename, UserInfo_t *info, size_t size);

// Synchronous read and write
int Read(int fd, char* buf, unsigned long offset,
unsigned long length); // NOLINT
int Write(int fd, const char* buf, unsigned long offset,
unsigned long length); // NOLINT
// Synchronous read and write
int Read(int fd, char *buf, unsigned long offset,
unsigned long length); // NOLINT
int Write(int fd, const char *buf, unsigned long offset,
unsigned long length); // NOLINT

// Asynchronous read and write
int AioRead(int fd, AioContext* aioctx);
int AioWrite(int fd, AioContext* aioctx);
// Asynchronous read and write
int AioRead(int fd, AioContext *aioctx);
int AioWrite(int fd, AioContext *aioctx);

// Obtain basic information about the file
int StatFile4Qemu(const char* filename, FileInfo_t* finfo);
int StatFile(const char* filename, UserInfo_t* info, FileInfo_t* finfo);
int ChangeOwner(const char* filename, const char* owner, UserInfo_t* info);
int Close(int fd);
// Obtain basic information about the file
int StatFile4Qemu(const char *filename, FileInfo_t *finfo);
int StatFile(const char *filename, UserInfo_t *info, FileInfo_t *finfo);
int ChangeOwner(const char *filename, const char *owner, UserInfo_t *info);
int Close(int fd);

int Rename(UserInfo_t* info, const char* oldpath, const char* newpath);
int Extend(const char* filename, UserInfo_t* info, uint64_t size);
int Unlink(const char* filename, UserInfo_t* info);
int Recover(const char* filename, UserInfo_t* info, uint64_t fileId);
int DeleteForce(const char* filename, UserInfo_t* info);
DirInfos_t* OpenDir(const char* dirpath, UserInfo_t* userinfo);
void CloseDir(DirInfos_t* dirinfo);
int Listdir(DirInfos_t* dirinfo);
int Mkdir(const char* dirpath, UserInfo_t* info);
int Rmdir(const char* dirpath, UserInfo_t* info);
int Rename(UserInfo_t *info, const char *oldpath, const char *newpath);
int Extend(const char *filename, UserInfo_t *info, uint64_t size);
int Unlink(const char *filename, UserInfo_t *info);
int Recover(const char *filename, UserInfo_t *info, uint64_t fileId);
int DeleteForce(const char *filename, UserInfo_t *info);
DirInfos_t *OpenDir(const char *dirpath, UserInfo_t *userinfo);
void CloseDir(DirInfos_t *dirinfo);
int Listdir(DirInfos_t *dirinfo);
int Mkdir(const char *dirpath, UserInfo_t *info);
int Rmdir(const char *dirpath, UserInfo_t *info);

void UnInit();
void UnInit();

int GetClusterId(char* buf = nullptr, int len = 0);
int GetClusterId(char *buf = nullptr, int len = 0);

#ifdef __cplusplus
}
#endif

#endif // !CURVE_LIBCURVE_INTERFACE_H //NOLINT
#endif // !CURVE_LIBCURVE_INTERFACE_H //NOLINT
149 changes: 78 additions & 71 deletions nebd/src/common/name_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,80 +25,87 @@

#include <atomic>
#include <memory>
#include <mutex> // NOLINT
#include <mutex> // NOLINT
#include <string>
#include <unordered_map>
#include <vector>

#include "nebd/src/common/uncopyable.h"

namespace nebd {
namespace common {

class NameLock : public Uncopyable {
public:
explicit NameLock(int bucketNum = 256);

/**
* @brief locks the specified string
*
* @param lockStr locked string
*/
void Lock(const std::string& lockStr);

/**
* @brief Attempt to specify sting lock
*
* @param lockStr locked string
*
* @retval succeeded
* @retval failed
*/
bool TryLock(const std::string& lockStr);

/**
* @brief unlocks the specified string
*
* @param lockStr locked string
*/
void Unlock(const std::string& lockStr);

private:
struct LockEntry {
std::atomic<uint32_t> ref_;
std::mutex lock_;
};
using LockEntryPtr = std::shared_ptr<LockEntry>;

struct LockBucket {
std::mutex mu;
std::unordered_map<std::string, LockEntryPtr> lockMap;
};
using LockBucketPtr = std::shared_ptr<LockBucket>;

int GetBucketOffset(const std::string& lockStr);

private:
std::vector<LockBucketPtr> locks_;
};

class NameLockGuard : public Uncopyable {
public:
NameLockGuard(NameLock& lock, const std::string& lockStr)
: // NOLINT
lock_(lock),
lockStr_(lockStr) {
lock_.Lock(lockStr_);
}

~NameLockGuard() { lock_.Unlock(lockStr_); }

private:
NameLock& lock_;
std::string lockStr_;
};

} // namespace common
} // namespace nebd

#endif // NEBD_SRC_COMMON_NAME_LOCK_H_
namespace nebd
{
namespace common
{

class NameLock : public Uncopyable
{
public:
explicit NameLock(int bucketNum = 256);

/**
* @brief locks the specified string
*
* @param lockStr locked string
*/
void Lock(const std::string &lockStr);

/**
* @brief Attempt to specify sting lock
*
* @param lockStr locked string
*
* @retval succeeded
* @retval failed
*/
bool TryLock(const std::string &lockStr);

/**
* @brief unlocks the specified string
*
* @param lockStr locked string
*/
void Unlock(const std::string &lockStr);

private:
struct LockEntry
{
std::atomic<uint32_t> ref_;
std::mutex lock_;
};
using LockEntryPtr = std::shared_ptr<LockEntry>;

struct LockBucket
{
std::mutex mu;
std::unordered_map<std::string, LockEntryPtr> lockMap;
};
using LockBucketPtr = std::shared_ptr<LockBucket>;

int GetBucketOffset(const std::string &lockStr);

private:
std::vector<LockBucketPtr> locks_;
};

class NameLockGuard : public Uncopyable
{
public:
NameLockGuard(NameLock &lock, const std::string &lockStr)
: // NOLINT
lock_(lock),
lockStr_(lockStr)
{
lock_.Lock(lockStr_);
}

~NameLockGuard() { lock_.Unlock(lockStr_); }

private:
NameLock &lock_;
std::string lockStr_;
};

} // namespace common
} // namespace nebd

#endif // NEBD_SRC_COMMON_NAME_LOCK_H_
Loading

0 comments on commit b0148e2

Please sign in to comment.