On Fri, Aug 12, 2011 at 2:48 PM, Michael Hanselmann <[email protected]> wrote:
> The original design for query2 specifically excluded locking, but now
> it's turned out that it would be a good thing to have in watcher. This
> patch adds a new parameter to OpQuery and enables its use in LUQuery. A
> missing function is added to LUGroupQuery, a comment clarified in
> _NodeQuery and all locks declared as shared acquires in the same LU.
>
> Signed-off-by: Michael Hanselmann <[email protected]>
> ---
>  lib/cmdlib.py  |    9 ++++++---
>  lib/opcodes.py |    1 +
>  2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/lib/cmdlib.py b/lib/cmdlib.py
> index 38811d0..1e0ac3e 100644
> --- a/lib/cmdlib.py
> +++ b/lib/cmdlib.py
> @@ -4343,7 +4343,7 @@ class _NodeQuery(_QueryBase):
>
>   def ExpandNames(self, lu):
>     lu.needed_locks = {}
> -    lu.share_locks[locking.LEVEL_NODE] = 1
> +    lu.share_locks = _ShareAll()
>
>     if self.names:
>       self.wanted = _GetWantedNodes(lu, self.names)
> @@ -4354,7 +4354,7 @@ class _NodeQuery(_QueryBase):
>                        query.NQ_LIVE in self.requested_data)
>
>     if self.do_locking:
> -      # if we don't request only static fields, we need to lock the nodes
> +      # If any non-static field is requested we need to lock the nodes
>       lu.needed_locks[locking.LEVEL_NODE] = self.wanted
>
>   def DeclareLocks(self, lu, level):
> @@ -4726,7 +4726,7 @@ class LUQuery(NoHooksLU):
>   def CheckArguments(self):
>     qcls = _GetQueryImplementation(self.op.what)
>
> -    self.impl = qcls(self.op.filter, self.op.fields, False)
> +    self.impl = qcls(self.op.filter, self.op.fields, self.op.use_locking)
>
>   def ExpandNames(self):
>     self.impl.ExpandNames(self)
> @@ -12062,6 +12062,9 @@ class LUGroupQuery(NoHooksLU):
>   def ExpandNames(self):
>     self.gq.ExpandNames(self)
>
> +  def DeclareLocks(self, level):
> +    self.gq.DeclareLocks(self, level)
> +
>   def Exec(self, feedback_fn):
>     return self.gq.OldStyleQuery(self)
>
> diff --git a/lib/opcodes.py b/lib/opcodes.py
> index a960d44..fe99b6e 100644
> --- a/lib/opcodes.py
> +++ b/lib/opcodes.py
> @@ -795,6 +795,7 @@ class OpQuery(OpCode):
>   OP_DSC_FIELD = "what"
>   OP_PARAMS = [
>     _PQueryWhat,
> +    _PUseLocking,
>     ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
>      "Requested fields"),
>     ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
> --
> 1.7.6

LGTM

>
>

Reply via email to