Skip to content

Commit 20aea27

Browse files
committed
Merge pull request #1765 from shapeblue/CLOUDSTACK-9586
Cloudstack 9586: When using local storage with Xenserver prepareTemplate does not work with multiple primary storeThe race condition will happen whenever there are multiple primary storages and the CS tries to mount the secondary store to xenserver host simultaneously. Due to synchronised block one mount will be successful and other thread will get the already mounted SR. Without the fix the two thread will try to mount it parallely and one will fail on Xenserver. * pr/1765: Cloudstack 9586: When using local storage with Xenserver prepareTemplate does not work with multiple primary store The race condition will happen whenever there are multiple primary storages and the CS tries to mount the secondary store to xenserver host simultaneously. Due to synchronised block one mount will be successful and other thread will get the already mounted SR. Without the fix the two thread will try to mount it parallely and one will fail on Xenserver. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 9e4246a + ba32ac1 commit 20aea27

1 file changed

Lines changed: 17 additions & 28 deletions

File tree

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/Xenserver625StorageProcessor.java

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,35 +101,24 @@ protected SR createFileSR(final Connection conn, final String path) {
101101

102102
try {
103103
final String srname = hypervisorResource.getHost().getUuid() + path.trim();
104-
105-
final Set<SR> srs = SR.getByNameLabel(conn, srname);
106-
107-
if (srs != null && !srs.isEmpty()) {
108-
return srs.iterator().next();
104+
synchronized (srname.intern()) {
105+
final Set<SR> srs = SR.getByNameLabel(conn, srname);
106+
if (srs != null && !srs.isEmpty()) {
107+
return srs.iterator().next();
108+
}
109+
final Map<String, String> smConfig = new HashMap<String, String>();
110+
final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
111+
final String uuid = UUID.randomUUID().toString();
112+
sr = SR.introduce(conn, uuid, srname, srname, "file", "file", false, smConfig);
113+
final PBD.Record record = new PBD.Record();
114+
record.host = host;
115+
record.SR = sr;
116+
smConfig.put("location", path);
117+
record.deviceConfig = smConfig;
118+
pbd = PBD.create(conn, record);
119+
pbd.plug(conn);
120+
sr.scan(conn);
109121
}
110-
111-
final Map<String, String> smConfig = new HashMap<String, String>();
112-
113-
final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
114-
final String uuid = UUID.randomUUID().toString();
115-
116-
sr = SR.introduce(conn, uuid, srname, srname, "file", "file", false, smConfig);
117-
118-
final PBD.Record record = new PBD.Record();
119-
120-
record.host = host;
121-
record.SR = sr;
122-
123-
smConfig.put("location", path);
124-
125-
record.deviceConfig = smConfig;
126-
127-
pbd = PBD.create(conn, record);
128-
129-
pbd.plug(conn);
130-
131-
sr.scan(conn);
132-
133122
return sr;
134123
} catch (final Exception ex) {
135124
try {

0 commit comments

Comments
 (0)