@@ -362,9 +362,6 @@ def load(self, sr_uuid):
362362 self ._linstor = None # Ensure that LINSTOR attribute exists.
363363 self ._journaler = None
364364
365- self ._is_master = False
366- if 'SRmaster' in self .dconf and self .dconf ['SRmaster' ] == 'true' :
367- self ._is_master = True
368365 self ._group_name = self .dconf ['group-name' ]
369366
370367 self ._vdi_shared_time = 0
@@ -437,7 +434,7 @@ def connect():
437434
438435 return wrapped_method (self , * args , ** kwargs )
439436
440- if not self ._is_master :
437+ if not self .is_master () :
441438 if self .cmd in [
442439 'sr_create' , 'sr_delete' , 'sr_update' , 'sr_probe' ,
443440 'sr_scan' , 'vdi_create' , 'vdi_delete' , 'vdi_resize' ,
@@ -472,7 +469,7 @@ def connect():
472469
473470 # Ensure we use a non-locked volume when vhdutil is called.
474471 if (
475- self ._is_master and self .cmd .startswith ('vdi_' ) and
472+ self .is_master () and self .cmd .startswith ('vdi_' ) and
476473 self .cmd != 'vdi_create'
477474 ):
478475 self ._linstor .ensure_volume_is_not_locked (
@@ -487,7 +484,7 @@ def connect():
487484 #
488485 # If the command is a SR command we want at least to remove
489486 # resourceless volumes.
490- if self ._is_master and self .cmd not in [
487+ if self .is_master () and self .cmd not in [
491488 'vdi_attach' , 'vdi_detach' ,
492489 'vdi_activate' , 'vdi_deactivate' ,
493490 'vdi_epoch_begin' , 'vdi_epoch_end' ,
@@ -783,6 +780,15 @@ def scan(self, uuid):
783780 self ._kick_gc ()
784781 return ret
785782
783+ def is_master (self ):
784+ if not hasattr (self , '_is_master' ):
785+ if 'SRmaster' not in self .dconf :
786+ self ._is_master = self .session is not None and util .is_master (self .session )
787+ else :
788+ self ._is_master = self .dconf ['SRmaster' ] == 'true'
789+
790+ return self ._is_master
791+
786792 @_locked_load
787793 def vdi (self , uuid ):
788794 return LinstorVDI (self , uuid )
@@ -968,7 +974,7 @@ def _synchronize_metadata_and_xapi(self):
968974 )
969975
970976 def _synchronize_metadata (self ):
971- if not self ._is_master :
977+ if not self .is_master () :
972978 return
973979
974980 util .SMlog ('Synchronize metadata...' )
@@ -1015,7 +1021,7 @@ def _load_vdis(self):
10151021 if self ._vdis_loaded :
10161022 return
10171023
1018- assert self ._is_master
1024+ assert self .is_master ()
10191025
10201026 # We use a cache to avoid repeated JSON parsing.
10211027 # The performance gain is not big but we can still
@@ -1494,7 +1500,7 @@ def _reconnect(self):
14941500 controller_uri ,
14951501 self ._group_name ,
14961502 repair = (
1497- self ._is_master and
1503+ self .is_master () and
14981504 self .srcmd .cmd in self .ops_exclusive
14991505 ),
15001506 logger = util .SMlog
@@ -1796,7 +1802,7 @@ def attach(self, sr_uuid, vdi_uuid):
17961802 writable = 'args' not in self .sr .srcmd .params or \
17971803 self .sr .srcmd .params ['args' ][0 ] == 'true'
17981804
1799- if not attach_from_config or self .sr ._is_master :
1805+ if not attach_from_config or self .sr .is_master () :
18001806 # We need to inflate the volume if we don't have enough place
18011807 # to mount the VHD image. I.e. the volume capacity must be greater
18021808 # than the VHD size + bitmap size.
@@ -1878,7 +1884,7 @@ def detach(self, sr_uuid, vdi_uuid):
18781884 )
18791885
18801886 # We remove only on slaves because the volume can be used by the GC.
1881- if self .sr ._is_master :
1887+ if self .sr .is_master () :
18821888 return
18831889
18841890 while vdi_uuid :
@@ -1899,7 +1905,7 @@ def detach(self, sr_uuid, vdi_uuid):
18991905
19001906 def resize (self , sr_uuid , vdi_uuid , size ):
19011907 util .SMlog ('LinstorVDI.resize for {}' .format (self .uuid ))
1902- if not self .sr ._is_master :
1908+ if not self .sr .is_master () :
19031909 raise xs_errors .XenError (
19041910 'VDISize' ,
19051911 opterr = 'resize on slave not allowed'
@@ -2158,7 +2164,7 @@ def update(self, sr_uuid, vdi_uuid):
21582164 # --------------------------------------------------------------------------
21592165
21602166 def _prepare_thin (self , attach ):
2161- if self .sr ._is_master :
2167+ if self .sr .is_master () :
21622168 if attach :
21632169 attach_thin (
21642170 self .session , self .sr ._journaler , self ._linstor ,
@@ -2747,7 +2753,7 @@ def _attach_using_http_nbd(self):
27472753
27482754 # 0. Fetch drbd path.
27492755 must_get_device_path = True
2750- if not self .sr ._is_master :
2756+ if not self .sr .is_master () :
27512757 # We are on a slave, we must try to find a diskful locally.
27522758 try :
27532759 volume_info = self ._linstor .get_volume_info (self .uuid )
@@ -2762,7 +2768,7 @@ def _attach_using_http_nbd(self):
27622768 must_get_device_path = hostname in volume_info .diskful
27632769
27642770 drbd_path = None
2765- if must_get_device_path or self .sr ._is_master :
2771+ if must_get_device_path or self .sr .is_master () :
27662772 # If we are master, we must ensure we have a diskless
27672773 # or diskful available to init HA.
27682774 # It also avoid this error in xensource.log
0 commit comments