Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rbd.image scan stuck #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ceph_iscsi_config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ def manage(self, rqst_type, committer=None):

# persist the config update
config_object.commit()
if config_object.error:
self.error = True
self.error_msg = config_object.error_msg

elif rqst_type == 'reconfigure':
self.define_client()
Expand All @@ -685,6 +688,9 @@ def manage(self, rqst_type, committer=None):
target_config['clients'].pop(self.iqn)
config_object.update_item("targets", self.target_iqn, target_config)
config_object.commit()
if config_object.error:
self.error = True
self.error_msg = config_object.error_msg

else:
# desired state is absent, but the client does not exist
Expand Down
9 changes: 4 additions & 5 deletions ceph_iscsi_config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,12 @@ def unlock(self):

def _seed_rbd_config(self):

ioctx = self._open_ioctx()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: perhaps just use a with self._open_ioctx() as ioctx: block ....


self.lock()
if self.error:
return

# if the config object is empty, seed it - if not just leave as is
ioctx = self._open_ioctx()
cfg_data = self._read_config_object(ioctx)
if not cfg_data:
self.logger.debug("_seed_rbd_config found empty config object")
Expand All @@ -499,6 +498,7 @@ def _seed_rbd_config(self):
ioctx.set_xattr(self.config_name, "epoch", "0".encode('utf-8'))
self.changed = True

ioctx.close()
self.unlock()

def refresh(self):
Expand Down Expand Up @@ -591,15 +591,14 @@ def set_item(self, cfg_type, element_name, element_value):

def _commit_rbd(self, post_action):

ioctx = self._open_ioctx()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: same comment here


if not self.config_locked:
self.lock()
if self.error:
return

# reread the config to account for updates made by other systems
# then apply this hosts update(s)
ioctx = self._open_ioctx()
current_config = json.loads(self._read_config_object(ioctx))
for txn in self.txn_list:

Expand Down Expand Up @@ -638,8 +637,8 @@ def _commit_rbd(self, post_action):
str(current_config["epoch"]).encode('utf-8'))
del self.txn_list[:] # empty the list of transactions

self.unlock()
ioctx.close()
self.unlock()

if post_action == 'close':
self.ceph.shutdown()
Expand Down
9 changes: 6 additions & 3 deletions ceph_iscsi_config/lun.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def _get_size_bytes(self):
with rados.Rados(conffile=settings.config.cephconf,
name=settings.config.cluster_client_name) as cluster:
with cluster.open_ioctx(self.pool) as ioctx:
with rbd.Image(ioctx, self.image) as rbd_image:
with rbd.Image(ioctx, self.image, read_only=True) as rbd_image:
image_size = rbd_image.size()

return image_size
Expand Down Expand Up @@ -223,8 +223,7 @@ def _valid_rbd(self):
with rados.Rados(conffile=settings.config.cephconf,
name=settings.config.cluster_client_name) as cluster:
ioctx = cluster.open_ioctx(self.pool)
with rbd.Image(ioctx, self.image) as rbd_image:

with rbd.Image(ioctx, self.image, read_only=True) as rbd_image:
if rbd_image.features() & RBDDev.required_features(self.backstore) != \
RBDDev.required_features(self.backstore):
valid_state = False
Expand Down Expand Up @@ -367,6 +366,8 @@ def remove_lun(self, preserve_image):
self.config.del_item('disks', self.config_key)

self.config.commit()
self.error = self.config.error
self.error_msg = self.config.error_msg

def unmap_lun(self, target_iqn):
local_gw = this_host()
Expand Down Expand Up @@ -425,6 +426,8 @@ def unmap_lun(self, target_iqn):
self.config.update_item("disks", self.config_key, disk_metadata)

self.config.commit()
self.error = self.config.error
self.error_msg = self.config.error_msg

def _get_next_lun_id(self, target_disks):
lun_ids_in_use = [t['lun_id'] for t in target_disks.values()]
Expand Down
9 changes: 9 additions & 0 deletions ceph_iscsi_config/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ def manage(self, mode):

if self.config_updated:
config.commit()
if config.error:
self.error = True
self.error_msg = config.error_msg

elif mode == 'map':

Expand Down Expand Up @@ -698,6 +701,9 @@ def manage(self, mode):
}
config.add_item("targets", self.iqn, seed_target)
config.commit()
if config.error:
self.error = True
self.error_msg = config.error_msg

discovery_auth_config = config.config['discovery_auth']
Discovery.set_discovery_auth_lio(discovery_auth_config['username'],
Expand Down Expand Up @@ -744,6 +750,9 @@ def manage(self, mode):
config.del_item('gateways', local_gw)

config.commit()
if config.error:
self.error = True
self.error_msg = config.error_msg

@staticmethod
def get_num_sessions(target_iqn):
Expand Down
2 changes: 1 addition & 1 deletion ceph_iscsi_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def get_rbd_size(pool, image, conf=None):

with rados.Rados(conffile=conf, name=settings.config.cluster_client_name) as cluster:
with cluster.open_ioctx(pool) as ioctx:
with rbd.Image(ioctx, image) as rbd_image:
with rbd.Image(ioctx, image, read_only=True) as rbd_image:
size = rbd_image.size()
return size

Expand Down
4 changes: 2 additions & 2 deletions gwcli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _get_disk_meta(self, cluster_ioctx, disk_meta):
disk_meta[rbd_name] = {}
with cluster_ioctx.open_ioctx(pool) as ioctx:
try:
with rbd.Image(ioctx, image) as rbd_image:
with rbd.Image(ioctx, image, read_only=True) as rbd_image:
size = rbd_image.size()
features = rbd_image.features()
snapshots = list(rbd_image.list_snaps())
Expand Down Expand Up @@ -752,7 +752,7 @@ def _get_meta_data_tcmu(self):
name=settings.config.cluster_client_name) as cluster:
with cluster.open_ioctx(self.pool) as ioctx:
try:
with rbd.Image(ioctx, self.image) as rbd_image:
with rbd.Image(ioctx, self.image, read_only=True) as rbd_image:
self.exists = True
self.size = rbd_image.size()
self.size_h = human_size(self.size)
Expand Down