~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to net/tipc/bearer.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * net/tipc/bearer.c: TIPC bearer code
3
3
 *
4
4
 * Copyright (c) 1996-2006, Ericsson AB
5
 
 * Copyright (c) 2004-2006, Wind River Systems
 
5
 * Copyright (c) 2004-2006, 2010-2011, Wind River Systems
6
6
 * All rights reserved.
7
7
 *
8
8
 * Redistribution and use in source and binary forms, with or without
44
44
static struct media media_list[MAX_MEDIA];
45
45
static u32 media_count;
46
46
 
47
 
struct bearer tipc_bearers[MAX_BEARERS];
 
47
struct tipc_bearer tipc_bearers[MAX_BEARERS];
48
48
 
49
49
/**
50
50
 * media_name_valid - validate media name
158
158
        m_ptr->disable_bearer = disable;
159
159
        m_ptr->addr2str = addr2str;
160
160
        memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
161
 
        m_ptr->bcast = 1;
162
161
        strcpy(m_ptr->name, name);
163
162
        m_ptr->priority = bearer_priority;
164
163
        m_ptr->tolerance = link_tolerance;
278
277
 * bearer_find - locates bearer object with matching bearer name
279
278
 */
280
279
 
281
 
static struct bearer *bearer_find(const char *name)
 
280
static struct tipc_bearer *bearer_find(const char *name)
282
281
{
283
 
        struct bearer *b_ptr;
 
282
        struct tipc_bearer *b_ptr;
284
283
        u32 i;
285
284
 
286
285
        for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
287
 
                if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
 
286
                if (b_ptr->active && (!strcmp(b_ptr->name, name)))
288
287
                        return b_ptr;
289
288
        }
290
289
        return NULL;
294
293
 * tipc_bearer_find_interface - locates bearer object with matching interface name
295
294
 */
296
295
 
297
 
struct bearer *tipc_bearer_find_interface(const char *if_name)
 
296
struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
298
297
{
299
 
        struct bearer *b_ptr;
 
298
        struct tipc_bearer *b_ptr;
300
299
        char *b_if_name;
301
300
        u32 i;
302
301
 
303
302
        for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
304
303
                if (!b_ptr->active)
305
304
                        continue;
306
 
                b_if_name = strchr(b_ptr->publ.name, ':') + 1;
 
305
                b_if_name = strchr(b_ptr->name, ':') + 1;
307
306
                if (!strcmp(b_if_name, if_name))
308
307
                        return b_ptr;
309
308
        }
318
317
{
319
318
        struct sk_buff *buf;
320
319
        struct media *m_ptr;
321
 
        struct bearer *b_ptr;
 
320
        struct tipc_bearer *b_ptr;
322
321
        int i, j;
323
322
 
324
323
        buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
331
330
                        b_ptr = &tipc_bearers[j];
332
331
                        if (b_ptr->active && (b_ptr->media == m_ptr)) {
333
332
                                tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
334
 
                                                    b_ptr->publ.name,
335
 
                                                    strlen(b_ptr->publ.name) + 1);
 
333
                                                    b_ptr->name,
 
334
                                                    strlen(b_ptr->name) + 1);
336
335
                        }
337
336
                }
338
337
        }
340
339
        return buf;
341
340
}
342
341
 
343
 
void tipc_bearer_add_dest(struct bearer *b_ptr, u32 dest)
 
342
void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
344
343
{
345
344
        tipc_nmap_add(&b_ptr->nodes, dest);
346
345
        tipc_disc_update_link_req(b_ptr->link_req);
347
346
        tipc_bcbearer_sort();
348
347
}
349
348
 
350
 
void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
 
349
void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
351
350
{
352
351
        tipc_nmap_remove(&b_ptr->nodes, dest);
353
352
        tipc_disc_update_link_req(b_ptr->link_req);
362
361
 * bearer.lock must be taken before calling
363
362
 * Returns binary true(1) ore false(0)
364
363
 */
365
 
static int bearer_push(struct bearer *b_ptr)
 
364
static int bearer_push(struct tipc_bearer *b_ptr)
366
365
{
367
366
        u32 res = 0;
368
367
        struct link *ln, *tln;
369
368
 
370
 
        if (b_ptr->publ.blocked)
 
369
        if (b_ptr->blocked)
371
370
                return 0;
372
371
 
373
372
        while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
382
381
        return list_empty(&b_ptr->cong_links);
383
382
}
384
383
 
385
 
void tipc_bearer_lock_push(struct bearer *b_ptr)
 
384
void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
386
385
{
387
386
        int res;
388
387
 
389
 
        spin_lock_bh(&b_ptr->publ.lock);
 
388
        spin_lock_bh(&b_ptr->lock);
390
389
        res = bearer_push(b_ptr);
391
 
        spin_unlock_bh(&b_ptr->publ.lock);
 
390
        spin_unlock_bh(&b_ptr->lock);
392
391
        if (res)
393
392
                tipc_bcbearer_push();
394
393
}
398
397
 * Interrupt enabling new requests after bearer congestion or blocking:
399
398
 * See bearer_send().
400
399
 */
401
 
void tipc_continue(struct tipc_bearer *tb_ptr)
 
400
void tipc_continue(struct tipc_bearer *b_ptr)
402
401
{
403
 
        struct bearer *b_ptr = (struct bearer *)tb_ptr;
404
 
 
405
 
        spin_lock_bh(&b_ptr->publ.lock);
 
402
        spin_lock_bh(&b_ptr->lock);
406
403
        b_ptr->continue_count++;
407
404
        if (!list_empty(&b_ptr->cong_links))
408
405
                tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
409
 
        b_ptr->publ.blocked = 0;
410
 
        spin_unlock_bh(&b_ptr->publ.lock);
 
406
        b_ptr->blocked = 0;
 
407
        spin_unlock_bh(&b_ptr->lock);
411
408
}
412
409
 
413
410
/*
418
415
 * bearer.lock is busy
419
416
 */
420
417
 
421
 
static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_ptr)
 
418
static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
422
419
{
423
420
        list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
424
421
}
431
428
 * bearer.lock is free
432
429
 */
433
430
 
434
 
void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
 
431
void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
435
432
{
436
 
        spin_lock_bh(&b_ptr->publ.lock);
 
433
        spin_lock_bh(&b_ptr->lock);
437
434
        tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
438
 
        spin_unlock_bh(&b_ptr->publ.lock);
 
435
        spin_unlock_bh(&b_ptr->lock);
439
436
}
440
437
 
441
438
 
444
441
 * and if there is, try to resolve it before returning.
445
442
 * 'tipc_net_lock' is read_locked when this function is called
446
443
 */
447
 
int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr)
 
444
int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
448
445
{
449
446
        int res = 1;
450
447
 
451
448
        if (list_empty(&b_ptr->cong_links))
452
449
                return 1;
453
 
        spin_lock_bh(&b_ptr->publ.lock);
 
450
        spin_lock_bh(&b_ptr->lock);
454
451
        if (!bearer_push(b_ptr)) {
455
452
                tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
456
453
                res = 0;
457
454
        }
458
 
        spin_unlock_bh(&b_ptr->publ.lock);
 
455
        spin_unlock_bh(&b_ptr->lock);
459
456
        return res;
460
457
}
461
458
 
463
460
 * tipc_bearer_congested - determines if bearer is currently congested
464
461
 */
465
462
 
466
 
int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
 
463
int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
467
464
{
468
 
        if (unlikely(b_ptr->publ.blocked))
 
465
        if (unlikely(b_ptr->blocked))
469
466
                return 1;
470
467
        if (likely(list_empty(&b_ptr->cong_links)))
471
468
                return 0;
476
473
 * tipc_enable_bearer - enable bearer with the given name
477
474
 */
478
475
 
479
 
int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
 
476
int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
480
477
{
481
 
        struct bearer *b_ptr;
 
478
        struct tipc_bearer *b_ptr;
482
479
        struct media *m_ptr;
483
480
        struct bearer_name b_name;
484
481
        char addr_string[16];
496
493
                warn("Bearer <%s> rejected, illegal name\n", name);
497
494
                return -EINVAL;
498
495
        }
499
 
        if (!tipc_addr_domain_valid(bcast_scope) ||
500
 
            !tipc_in_scope(bcast_scope, tipc_own_addr)) {
501
 
                warn("Bearer <%s> rejected, illegal broadcast scope\n", name);
 
496
        if (!tipc_addr_domain_valid(disc_domain) ||
 
497
            !tipc_in_scope(disc_domain, tipc_own_addr)) {
 
498
                warn("Bearer <%s> rejected, illegal discovery domain\n", name);
502
499
                return -EINVAL;
503
500
        }
504
501
        if ((priority < TIPC_MIN_LINK_PRI ||
528
525
                        bearer_id = i;
529
526
                        continue;
530
527
                }
531
 
                if (!strcmp(name, tipc_bearers[i].publ.name)) {
 
528
                if (!strcmp(name, tipc_bearers[i].name)) {
532
529
                        warn("Bearer <%s> rejected, already enabled\n", name);
533
530
                        goto failed;
534
531
                }
551
548
        }
552
549
 
553
550
        b_ptr = &tipc_bearers[bearer_id];
554
 
        strcpy(b_ptr->publ.name, name);
555
 
        res = m_ptr->enable_bearer(&b_ptr->publ);
 
551
        strcpy(b_ptr->name, name);
 
552
        res = m_ptr->enable_bearer(b_ptr);
556
553
        if (res) {
557
554
                warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
558
555
                goto failed;
562
559
        b_ptr->media = m_ptr;
563
560
        b_ptr->net_plane = bearer_id + 'A';
564
561
        b_ptr->active = 1;
565
 
        b_ptr->detect_scope = bcast_scope;
566
562
        b_ptr->priority = priority;
567
563
        INIT_LIST_HEAD(&b_ptr->cong_links);
568
564
        INIT_LIST_HEAD(&b_ptr->links);
569
 
        if (m_ptr->bcast) {
570
 
                b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
571
 
                                                          bcast_scope, 2);
572
 
        }
573
 
        spin_lock_init(&b_ptr->publ.lock);
 
565
        b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
 
566
                                                  disc_domain);
 
567
        spin_lock_init(&b_ptr->lock);
574
568
        write_unlock_bh(&tipc_net_lock);
575
569
        info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
576
 
             name, tipc_addr_string_fill(addr_string, bcast_scope), priority);
 
570
             name, tipc_addr_string_fill(addr_string, disc_domain), priority);
577
571
        return 0;
578
572
failed:
579
573
        write_unlock_bh(&tipc_net_lock);
587
581
 
588
582
int tipc_block_bearer(const char *name)
589
583
{
590
 
        struct bearer *b_ptr = NULL;
 
584
        struct tipc_bearer *b_ptr = NULL;
591
585
        struct link *l_ptr;
592
586
        struct link *temp_l_ptr;
593
587
 
600
594
        }
601
595
 
602
596
        info("Blocking bearer <%s>\n", name);
603
 
        spin_lock_bh(&b_ptr->publ.lock);
604
 
        b_ptr->publ.blocked = 1;
 
597
        spin_lock_bh(&b_ptr->lock);
 
598
        b_ptr->blocked = 1;
605
599
        list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
606
600
                struct tipc_node *n_ptr = l_ptr->owner;
607
601
 
609
603
                tipc_link_reset(l_ptr);
610
604
                spin_unlock_bh(&n_ptr->lock);
611
605
        }
612
 
        spin_unlock_bh(&b_ptr->publ.lock);
 
606
        spin_unlock_bh(&b_ptr->lock);
613
607
        read_unlock_bh(&tipc_net_lock);
614
608
        return 0;
615
609
}
620
614
 * Note: This routine assumes caller holds tipc_net_lock.
621
615
 */
622
616
 
623
 
static void bearer_disable(struct bearer *b_ptr)
 
617
static void bearer_disable(struct tipc_bearer *b_ptr)
624
618
{
625
619
        struct link *l_ptr;
626
620
        struct link *temp_l_ptr;
627
621
 
628
 
        info("Disabling bearer <%s>\n", b_ptr->publ.name);
 
622
        info("Disabling bearer <%s>\n", b_ptr->name);
629
623
        tipc_disc_stop_link_req(b_ptr->link_req);
630
 
        spin_lock_bh(&b_ptr->publ.lock);
 
624
        spin_lock_bh(&b_ptr->lock);
631
625
        b_ptr->link_req = NULL;
632
 
        b_ptr->publ.blocked = 1;
633
 
        b_ptr->media->disable_bearer(&b_ptr->publ);
 
626
        b_ptr->blocked = 1;
 
627
        b_ptr->media->disable_bearer(b_ptr);
634
628
        list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
635
629
                tipc_link_delete(l_ptr);
636
630
        }
637
 
        spin_unlock_bh(&b_ptr->publ.lock);
638
 
        memset(b_ptr, 0, sizeof(struct bearer));
 
631
        spin_unlock_bh(&b_ptr->lock);
 
632
        memset(b_ptr, 0, sizeof(struct tipc_bearer));
639
633
}
640
634
 
641
635
int tipc_disable_bearer(const char *name)
642
636
{
643
 
        struct bearer *b_ptr;
 
637
        struct tipc_bearer *b_ptr;
644
638
        int res;
645
639
 
646
640
        write_lock_bh(&tipc_net_lock);