Skip to content

Commit bbece46

Browse files
committed
rgw: Add parameter to get_storage to indicate radosgw-admin call
Signed-off-by: Samarah <[email protected]>
1 parent 8f62e8f commit bbece46

File tree

8 files changed

+73
-69
lines changed

8 files changed

+73
-69
lines changed

src/rgw/driver/d4n/rgw_sal_d4n.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ static inline Object* nextObject(Object* t)
3636
return dynamic_cast<FilterObject*>(t)->get_next();
3737
}
3838

39-
D4NFilterDriver::D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context) : FilterDriver(_next),
40-
io_context(io_context),
41-
y(null_yield)
39+
D4NFilterDriver::D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context, bool admin) : FilterDriver(_next),
40+
io_context(io_context),
41+
y(null_yield)
4242
{
4343
rgw::cache::Partition partition_info;
4444
partition_info.location = g_conf()->rgw_d4n_l1_datacache_persistent_path;
4545
partition_info.name = "d4n";
4646
partition_info.type = "read-cache";
4747
partition_info.size = g_conf()->rgw_d4n_l1_datacache_size;
48-
cacheDriver = std::make_unique<rgw::cache::SSDDriver>(partition_info);
48+
cacheDriver = std::make_unique<rgw::cache::SSDDriver>(partition_info, admin);
4949
}
5050

5151
D4NFilterDriver::~D4NFilterDriver() = default;
@@ -3104,9 +3104,9 @@ int D4NFilterMultipartUpload::complete(const DoutPrefixProvider *dpp,
31043104

31053105
extern "C" {
31063106

3107-
rgw::sal::Driver* newD4NFilter(rgw::sal::Driver* next, void* io_context)
3107+
rgw::sal::Driver* newD4NFilter(rgw::sal::Driver* next, void* io_context, bool admin)
31083108
{
3109-
rgw::sal::D4NFilterDriver* driver = new rgw::sal::D4NFilterDriver(next, *static_cast<boost::asio::io_context*>(io_context));
3109+
rgw::sal::D4NFilterDriver* driver = new rgw::sal::D4NFilterDriver(next, *static_cast<boost::asio::io_context*>(io_context), admin);
31103110

31113111
return driver;
31123112
}

src/rgw/driver/d4n/rgw_sal_d4n.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class D4NFilterDriver : public FilterDriver {
6363
optional_yield y;
6464

6565
public:
66-
D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context);
66+
D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context, bool admin);
6767
virtual ~D4NFilterDriver();
6868

6969
virtual int initialize(CephContext *cct, const DoutPrefixProvider *dpp) override;

src/rgw/radosgw-admin/radosgw-admin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4641,7 +4641,7 @@ int main(int argc, const char **argv)
46414641
null_yield,
46424642
cfgstore.get(),
46434643
need_cache && g_conf()->rgw_cache_enabled,
4644-
need_gc);
4644+
need_gc, true /* admin */);
46454645
}
46464646
if (!driver) {
46474647
cerr << "couldn't init storage provider" << std::endl;

src/rgw/rgw_sal.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern rgw::sal::Driver* newPOSIXDriver(rgw::sal::Driver* next);
6565
#endif
6666
extern rgw::sal::Driver* newBaseFilter(rgw::sal::Driver* next);
6767
#ifdef WITH_RADOSGW_D4N
68-
extern rgw::sal::Driver* newD4NFilter(rgw::sal::Driver* next, boost::asio::io_context& io_context);
68+
extern rgw::sal::Driver* newD4NFilter(rgw::sal::Driver* next, boost::asio::io_context& io_context, bool admin);
6969
#endif
7070
}
7171

@@ -84,7 +84,7 @@ rgw::sal::Driver* DriverManager::init_storage_provider(const DoutPrefixProvider*
8484
bool use_cache,
8585
bool use_gc,
8686
bool background_tasks,
87-
optional_yield y, rgw::sal::ConfigStore* cfgstore)
87+
optional_yield y, rgw::sal::ConfigStore* cfgstore, bool admin)
8888
{
8989
rgw::sal::Driver* driver{nullptr};
9090

@@ -215,7 +215,7 @@ rgw::sal::Driver* DriverManager::init_storage_provider(const DoutPrefixProvider*
215215
#ifdef WITH_RADOSGW_D4N
216216
else if (cfg.filter_name.compare("d4n") == 0) {
217217
rgw::sal::Driver* next = driver;
218-
driver = newD4NFilter(next, io_context);
218+
driver = newD4NFilter(next, io_context, admin);
219219

220220
if (driver->initialize(cct, dpp) < 0) {
221221
delete driver;

src/rgw/rgw_sal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,8 @@ class DriverManager {
19431943
optional_yield y,
19441944
rgw::sal::ConfigStore* cfgstore,
19451945
bool use_cache = true,
1946-
bool use_gc = true) {
1946+
bool use_gc = true,
1947+
bool admin = false) {
19471948
rgw::sal::Driver* driver = init_storage_provider(dpp, cct, cfg, io_context,
19481949
site_config,
19491950
use_gc_thread,
@@ -1954,7 +1955,7 @@ class DriverManager {
19541955
run_reshard_thread,
19551956
run_notification_thread,
19561957
use_cache, use_gc,
1957-
background_tasks, y, cfgstore);
1958+
background_tasks, y, cfgstore, admin);
19581959
return driver;
19591960
}
19601961
/** Get a stripped down driver by service name */
@@ -1984,7 +1985,7 @@ class DriverManager {
19841985
bool run_notification_thread,
19851986
bool use_metadata_cache,
19861987
bool use_gc, bool background_tasks,
1987-
optional_yield y, rgw::sal::ConfigStore* cfgstore);
1988+
optional_yield y, rgw::sal::ConfigStore* cfgstore, bool admin);
19881989
/** Initialize a new raw Driver */
19891990
static rgw::sal::Driver* init_raw_storage_provider(const DoutPrefixProvider* dpp,
19901991
CephContext* cct,

src/rgw/rgw_ssd_driver.cc

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -116,59 +116,61 @@ int SSDDriver::initialize(const DoutPrefixProvider* dpp)
116116
partition_info.location += "/";
117117
}
118118

119-
try {
120-
if (efs::exists(partition_info.location)) {
121-
if (dpp->get_cct()->_conf->rgw_d4n_l1_evict_cache_on_start) {
122-
ldpp_dout(dpp, 5) << "initialize: evicting the persistent storage directory on start" << dendl;
123-
124-
uid_t uid = dpp->get_cct()->get_set_uid();
125-
gid_t gid = dpp->get_cct()->get_set_gid();
126-
127-
ldpp_dout(dpp, 5) << "initialize:: uid is " << uid << " and gid is " << gid << dendl;
128-
ldpp_dout(dpp, 5) << "initialize:: changing permissions for datacache directory." << dendl;
129-
130-
if (uid) {
131-
if (chown(partition_info.location.c_str(), uid, gid) == -1) {
132-
ldpp_dout(dpp, 5) << "initialize: chown return error: " << strerror(errno) << dendl;
133-
}
134-
135-
if (chmod(partition_info.location.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
136-
ldpp_dout(dpp, 5) << "initialize: chmod return error: " << strerror(errno) << dendl;
137-
}
138-
}
139-
140-
for (auto& p : efs::directory_iterator(partition_info.location)) {
141-
efs::remove_all(p.path());
142-
}
143-
}
144-
} else {
145-
ldpp_dout(dpp, 5) << "initialize:: creating the persistent storage directory on start: " << partition_info.location << dendl;
146-
std::error_code ec;
147-
if (!efs::create_directories(partition_info.location, ec)) {
148-
ldpp_dout(dpp, 0) << "initialize::: ERROR initializing the cache storage directory: '" << partition_info.location <<
149-
"' : " << ec.value() << dendl;
150-
} else {
151-
uid_t uid = dpp->get_cct()->get_set_uid();
152-
gid_t gid = dpp->get_cct()->get_set_gid();
153-
154-
ldpp_dout(dpp, 5) << "initialize:: uid is " << uid << " and gid is " << gid << dendl;
155-
ldpp_dout(dpp, 5) << "initialize:: changing permissions for datacache directory." << dendl;
156-
157-
if (uid) {
158-
if (chown(partition_info.location.c_str(), uid, gid) == -1) {
159-
ldpp_dout(dpp, 5) << "initialize: chown return error: " << strerror(errno) << dendl;
160-
}
161-
162-
if (chmod(partition_info.location.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
163-
ldpp_dout(dpp, 5) << "initialize: chmod return error: " << strerror(errno) << dendl;
164-
}
165-
}
166-
}
167-
}
168-
} catch (const efs::filesystem_error& e) {
169-
ldpp_dout(dpp, 0) << "initialize::: ERROR initializing the cache storage directory '" << partition_info.location <<
170-
"' : " << e.what() << dendl;
171-
//return -EINVAL; Should return error from here?
119+
if (!admin) { // Only initialize or evict cache if radosgw-admin is not responsible for call
120+
try {
121+
if (efs::exists(partition_info.location)) {
122+
if (dpp->get_cct()->_conf->rgw_d4n_l1_evict_cache_on_start) {
123+
ldpp_dout(dpp, 5) << "initialize: evicting the persistent storage directory on start" << dendl;
124+
125+
uid_t uid = dpp->get_cct()->get_set_uid();
126+
gid_t gid = dpp->get_cct()->get_set_gid();
127+
128+
ldpp_dout(dpp, 5) << "initialize:: uid is " << uid << " and gid is " << gid << dendl;
129+
ldpp_dout(dpp, 5) << "initialize:: changing permissions for datacache directory." << dendl;
130+
131+
if (uid) {
132+
if (chown(partition_info.location.c_str(), uid, gid) == -1) {
133+
ldpp_dout(dpp, 5) << "initialize: chown return error: " << strerror(errno) << dendl;
134+
}
135+
136+
if (chmod(partition_info.location.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
137+
ldpp_dout(dpp, 5) << "initialize: chmod return error: " << strerror(errno) << dendl;
138+
}
139+
}
140+
141+
for (auto& p : efs::directory_iterator(partition_info.location)) {
142+
efs::remove_all(p.path());
143+
}
144+
}
145+
} else {
146+
ldpp_dout(dpp, 5) << "initialize:: creating the persistent storage directory on start: " << partition_info.location << dendl;
147+
std::error_code ec;
148+
if (!efs::create_directories(partition_info.location, ec)) {
149+
ldpp_dout(dpp, 0) << "initialize::: ERROR initializing the cache storage directory: '" << partition_info.location <<
150+
"' : " << ec.value() << dendl;
151+
} else {
152+
uid_t uid = dpp->get_cct()->get_set_uid();
153+
gid_t gid = dpp->get_cct()->get_set_gid();
154+
155+
ldpp_dout(dpp, 5) << "initialize:: uid is " << uid << " and gid is " << gid << dendl;
156+
ldpp_dout(dpp, 5) << "initialize:: changing permissions for datacache directory." << dendl;
157+
158+
if (uid) {
159+
if (chown(partition_info.location.c_str(), uid, gid) == -1) {
160+
ldpp_dout(dpp, 5) << "initialize: chown return error: " << strerror(errno) << dendl;
161+
}
162+
163+
if (chmod(partition_info.location.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == -1) {
164+
ldpp_dout(dpp, 5) << "initialize: chmod return error: " << strerror(errno) << dendl;
165+
}
166+
}
167+
}
168+
}
169+
} catch (const efs::filesystem_error& e) {
170+
ldpp_dout(dpp, 0) << "initialize::: ERROR initializing the cache storage directory '" << partition_info.location <<
171+
"' : " << e.what() << dendl;
172+
//return -EINVAL; Should return error from here?
173+
}
172174
}
173175

174176
#if defined(HAVE_LIBAIO) && defined(__GLIBC__)

src/rgw/rgw_ssd_driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace rgw { namespace cache {
88

99
class SSDDriver : public CacheDriver {
1010
public:
11-
SSDDriver(Partition& partition_info) : partition_info(partition_info) {}
11+
SSDDriver(Partition& partition_info, bool admin) : partition_info(partition_info), admin(admin) {}
1212
virtual ~SSDDriver() {}
1313

1414
virtual int initialize(const DoutPrefixProvider* dpp) override;
@@ -39,6 +39,7 @@ class SSDDriver : public CacheDriver {
3939
uint64_t free_space;
4040
CephContext* cct;
4141
std::mutex cache_lock;
42+
bool admin;
4243

4344
struct libaio_read_handler {
4445
rgw::Aio* throttle = nullptr;

src/test/rgw/test_ssd_driver.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class SSDDriverFixture: public ::testing::Test {
8787
protected:
8888
virtual void SetUp() {
8989
rgw::cache::Partition partition_info{.name = "d4n", .type = "read-cache", .location = "rgw_d4n_datacache", .size = 5368709120};
90-
cacheDriver = new rgw::cache::SSDDriver{partition_info};
90+
cacheDriver = new rgw::cache::SSDDriver{partition_info, false};
9191

9292
ASSERT_NE(cacheDriver, nullptr);
9393

0 commit comments

Comments
 (0)