Move locking/unlocking code.

Datastores should only be dealing with datastores.

Change-Id: Ic6869fc38b97c6375d893c5fd19acca56c6516fc