Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 144333
b: refs/heads/master
c: f3784d8
h: refs/heads/master
i:
  144331: 8c447e0
v: v3
  • Loading branch information
Roger Quadros authored and Marcel Holtmann committed Apr 28, 2009
1 parent 6f1516b commit 2930425
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 227 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 942e4a2bd680c606af0211e64eb216be2e19bf61
refs/heads/master: f3784d834c71689336fa272df420b45345cb6b84
73 changes: 5 additions & 68 deletions trunk/include/linux/netfilter/x_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ struct xt_table
/* What hooks you will enter on */
unsigned int valid_hooks;

/* Lock for the curtain */
struct mutex lock;

/* Man behind the curtain... */
struct xt_table_info *private;

Expand Down Expand Up @@ -431,74 +434,8 @@ extern void xt_proto_fini(struct net *net, u_int8_t af);

extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
extern void xt_free_table_info(struct xt_table_info *info);

/*
* Per-CPU spinlock associated with per-cpu table entries, and
* with a counter for the "reading" side that allows a recursive
* reader to avoid taking the lock and deadlocking.
*
* "reading" is used by ip/arp/ip6 tables rule processing which runs per-cpu.
* It needs to ensure that the rules are not being changed while the packet
* is being processed. In some cases, the read lock will be acquired
* twice on the same CPU; this is okay because of the count.
*
* "writing" is used when reading counters.
* During replace any readers that are using the old tables have to complete
* before freeing the old table. This is handled by the write locking
* necessary for reading the counters.
*/
struct xt_info_lock {
spinlock_t lock;
unsigned char readers;
};
DECLARE_PER_CPU(struct xt_info_lock, xt_info_locks);

/*
* Note: we need to ensure that preemption is disabled before acquiring
* the per-cpu-variable, so we do it as a two step process rather than
* using "spin_lock_bh()".
*
* We _also_ need to disable bottom half processing before updating our
* nesting count, to make sure that the only kind of re-entrancy is this
* code being called by itself: since the count+lock is not an atomic
* operation, we can allow no races.
*
* _Only_ that special combination of being per-cpu and never getting
* re-entered asynchronously means that the count is safe.
*/
static inline void xt_info_rdlock_bh(void)
{
struct xt_info_lock *lock;

local_bh_disable();
lock = &__get_cpu_var(xt_info_locks);
if (!lock->readers++)
spin_lock(&lock->lock);
}

static inline void xt_info_rdunlock_bh(void)
{
struct xt_info_lock *lock = &__get_cpu_var(xt_info_locks);

if (!--lock->readers)
spin_unlock(&lock->lock);
local_bh_enable();
}

/*
* The "writer" side needs to get exclusive access to the lock,
* regardless of readers. This must be called with bottom half
* processing (and thus also preemption) disabled.
*/
static inline void xt_info_wrlock(unsigned int cpu)
{
spin_lock(&per_cpu(xt_info_locks, cpu).lock);
}

static inline void xt_info_wrunlock(unsigned int cpu)
{
spin_unlock(&per_cpu(xt_info_locks, cpu).lock);
}
extern void xt_table_entry_swap_rcu(struct xt_table_info *old,
struct xt_table_info *new);

/*
* This helper is performance critical and must be inlined
Expand Down
3 changes: 2 additions & 1 deletion trunk/include/net/bluetooth/hci_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ struct hci_conn {
struct timer_list disc_timer;
struct timer_list idle_timer;

struct work_struct work;
struct work_struct work_add;
struct work_struct work_del;

struct device dev;

Expand Down
37 changes: 16 additions & 21 deletions trunk/net/bluetooth/hci_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
struct class *bt_class = NULL;
EXPORT_SYMBOL_GPL(bt_class);

static struct workqueue_struct *btaddconn;
static struct workqueue_struct *btdelconn;
static struct workqueue_struct *bluetooth;

static inline char *link_typetostr(int type)
{
Expand Down Expand Up @@ -88,9 +87,10 @@ static struct device_type bt_link = {

static void add_conn(struct work_struct *work)
{
struct hci_conn *conn = container_of(work, struct hci_conn, work);
struct hci_conn *conn = container_of(work, struct hci_conn, work_add);

flush_workqueue(btdelconn);
/* ensure previous add/del is complete */
flush_workqueue(bluetooth);

if (device_add(&conn->dev) < 0) {
BT_ERR("Failed to register connection device");
Expand All @@ -114,9 +114,9 @@ void hci_conn_add_sysfs(struct hci_conn *conn)

device_initialize(&conn->dev);

INIT_WORK(&conn->work, add_conn);
INIT_WORK(&conn->work_add, add_conn);

queue_work(btaddconn, &conn->work);
queue_work(bluetooth, &conn->work_add);
}

/*
Expand All @@ -131,9 +131,12 @@ static int __match_tty(struct device *dev, void *data)

static void del_conn(struct work_struct *work)
{
struct hci_conn *conn = container_of(work, struct hci_conn, work);
struct hci_conn *conn = container_of(work, struct hci_conn, work_del);
struct hci_dev *hdev = conn->hdev;

/* ensure previous add/del is complete */
flush_workqueue(bluetooth);

while (1) {
struct device *dev;

Expand All @@ -156,9 +159,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn)
if (!device_is_registered(&conn->dev))
return;

INIT_WORK(&conn->work, del_conn);
INIT_WORK(&conn->work_del, del_conn);

queue_work(btdelconn, &conn->work);
queue_work(bluetooth, &conn->work_del);
}

static inline char *host_typetostr(int type)
Expand Down Expand Up @@ -435,20 +438,13 @@ void hci_unregister_sysfs(struct hci_dev *hdev)

int __init bt_sysfs_init(void)
{
btaddconn = create_singlethread_workqueue("btaddconn");
if (!btaddconn)
return -ENOMEM;

btdelconn = create_singlethread_workqueue("btdelconn");
if (!btdelconn) {
destroy_workqueue(btaddconn);
bluetooth = create_singlethread_workqueue("bluetooth");
if (!bluetooth)
return -ENOMEM;
}

bt_class = class_create(THIS_MODULE, "bluetooth");
if (IS_ERR(bt_class)) {
destroy_workqueue(btdelconn);
destroy_workqueue(btaddconn);
destroy_workqueue(bluetooth);
return PTR_ERR(bt_class);
}

Expand All @@ -457,8 +453,7 @@ int __init bt_sysfs_init(void)

void bt_sysfs_cleanup(void)
{
destroy_workqueue(btaddconn);
destroy_workqueue(btdelconn);
destroy_workqueue(bluetooth);

class_destroy(bt_class);
}
Loading

0 comments on commit 2930425

Please sign in to comment.