Linux bluetooth development
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v3 03/16] Bluetooth: Add initial skeleton for HCI transaction framework
Date: Fri, 1 Mar 2013 12:03:20 +0200	[thread overview]
Message-ID: <20130301100320.GA20590@x220.P-661HNU-F1> (raw)
In-Reply-To: <01E8737B-3E6B-4FF5-B281-C262E85442B7@holtmann.org>

Hi Marcel,

On Thu, Feb 28, 2013, Marcel Holtmann wrote:
> >>> +int hci_transaction_run(struct hci_transaction *transaction)
> >>> +{
> >>> +	struct hci_dev *hdev = transaction->hdev;
> >>> +
> >>> +	BT_DBG("length %u", skb_queue_len(&transaction->cmd_q));
> >>> +
> >>> +	/* Do not allow empty transactions */
> >>> +	if (skb_queue_empty(&transaction->cmd_q))
> >>> +		return -EINVAL;
> >>> +
> >>> +	spin_lock(&hdev->cmd_q.lock);
> >>> +	skb_queue_splice_tail(&transaction->cmd_q, &hdev->cmd_q);
> >>> +	spin_unlock(&hdev->cmd_q.lock);
> >>> +
> >>> +	queue_work(hdev->workqueue, &hdev->cmd_work);
> >>> +
> >>> +	return 0;
> >>> +}
> >> 
> >> I am wondering why we are not giving the complete handler when
> >> finishing the transaction. Having a copy of the handler in hci_dev
> >> structure seems a bit pointless. What is the reason here?
> > 
> > The hdev->transaction_complete is not related to building transactions
> > but for running them. I can move giving the callback to the
> > transaction_run function and thereby remove the need to store it in
> > struct hci_transaction, but the fact remains that it still needs to be
> > copied to the first skb of the transaction (since the moment we start
> > processing the transaction the callback needs to be copied to
> > hdev->transaction_complete). Storing the callback in struct
> > hci_transaction made it easy to copy it to the first skb when
> > hci_transaction_cmd() gets called for the first time on the transaction.
> > 
> > So let me repeat, we need the hdev->complete_transaction since the
> > callback could be needed for any individual HCI command that's part of
> > the transaction in case that command fails (since then we stop
> > processing the transaction and call the callback). Because of this the
> > callback needs to be part of the first skb of the transaction.
> 
> The way I see this is that if one command of the transaction fails, we
> need to not continue and just discard the rest of the transaction. Why
> not just go through the queue and find the complete callback attached
> with the last skb of transaction. Either that is the last successful
> command, or we had to go and remove the rest of the queue.

A command that completes it not part of hdev->cmd_q anymore but can be
found in hdev->sent_cmd instead. This means that to find the complete
callback we first need to check for
bt_cb(hdev->sent_cmd)->transaction.complete and if it's NULL start going
through hdev->cmd_q. This is more complicated than just checking for
hdev->transaction_complete, but if you think it's worth not having to
add another hdev member then I'll go with it.

Another problem is that the control buffer gets lost when doing
skb_clone. This means we have to add a memcpy of the skb->cb after doing
the hdev->sent_cmd = skb_clone(skb) in hci_cmd_work.

> This reminds me. Have you tested this with random commands in the
> transaction failing?

I *think* I tested it, but I'll make sure to do it at least before
sending the next patch set iteration.

Johan

  reply	other threads:[~2013-03-01 10:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-27  7:57 [PATCH v3 00/16] Bluetooth: Add HCI transaction framework Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 01/16] Bluetooth: Fix __hci_request() handling of empty requests Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 02/16] Bluetooth: Split HCI init sequence into three stages Johan Hedberg
2013-02-28 19:54   ` Marcel Holtmann
2013-03-01  6:55     ` Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 03/16] Bluetooth: Add initial skeleton for HCI transaction framework Johan Hedberg
2013-02-28 19:52   ` Marcel Holtmann
2013-03-01  7:04     ` Johan Hedberg
2013-03-01  7:30       ` Marcel Holtmann
2013-03-01 10:03         ` Johan Hedberg [this message]
2013-03-01 10:10           ` Johan Hedberg
2013-03-01 16:07             ` Marcel Holtmann
2013-03-01 16:13           ` Marcel Holtmann
2013-02-27  7:57 ` [PATCH v3 04/16] Bluetooth: Refactor HCI command skb creation Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 05/16] Bluetooth: Introduce new hci_transaction_cmd function Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 06/16] Bluetooth: Introduce a hci_transaction_from_skb function Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 07/16] Bluetooth: Add transaction cmd_complete and cmd_status functions Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 08/16] Bluetooth: Convert hci_request to use HCI transaction framework Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 09/16] Bluetooth: Remove unused hdev->init_last_cmd Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 10/16] Bluetooth: Move power on HCI command updates to their own function Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 11/16] Bluetooth: Update mgmt powered HCI commands to use transactions Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 12/16] Bluetooth: Wait for HCI command completion with mgmt_set_powered Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 13/16] Bluetooth: Fix busy condition testing for EIR and class updates Johan Hedberg
2013-02-28 20:01   ` Marcel Holtmann
2013-03-01  7:32     ` Johan Hedberg
2013-03-01  8:00       ` Marcel Holtmann
2013-03-01  8:39         ` Johan Hedberg
2013-03-01 16:02           ` Marcel Holtmann
2013-02-27  7:57 ` [PATCH v3 14/16] Bluetooth: Fix UUID/class mgmt command response synchronization Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 15/16] Bluetooth: Remove useless HCI_PENDING_CLASS flag Johan Hedberg
2013-02-27  7:57 ` [PATCH v3 16/16] Bluetooth: Remove empty HCI event handlers Johan Hedberg
2013-02-28 23:05 ` [PATCH v3 00/16] Bluetooth: Add HCI transaction framework Vinicius Costa Gomes
2013-03-01  8:46   ` Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130301100320.GA20590@x220.P-661HNU-F1 \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox