aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 07:25:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-25 07:25:22 -0400
commit8a9ea3237e7eb5c25f09e429ad242ae5a3d5ea22 (patch)
treea0a63398a9983667d52cbbbf4e2405b4f22b1d83 /fs/sysfs
parent1be025d3cb40cd295123af2c394f7229ef9b30ca (diff)
parent8b3408f8ee994973869d8ba32c5bf482bc4ddca4 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1745 commits) dp83640: free packet queues on remove dp83640: use proper function to free transmit time stamping packets ipv6: Do not use routes from locally generated RAs |PATCH net-next] tg3: add tx_dropped counter be2net: don't create multiple RX/TX rings in multi channel mode be2net: don't create multiple TXQs in BE2 be2net: refactor VF setup/teardown code into be_vf_setup/clear() be2net: add vlan/rx-mode/flow-control config to be_setup() net_sched: cls_flow: use skb_header_pointer() ipv4: avoid useless call of the function check_peer_pmtu TCP: remove TCP_DEBUG net: Fix driver name for mdio-gpio.c ipv4: tcp: fix TOS value in ACK messages sent from TIME_WAIT rtnetlink: Add missing manual netlink notification in dev_change_net_namespaces ipv4: fix ipsec forward performance regression jme: fix irq storm after suspend/resume route: fix ICMP redirect validation net: hold sock reference while processing tx timestamps tcp: md5: add more const attributes Add ethtool -g support to virtio_net ... Fix up conflicts in: - drivers/net/Kconfig: The split-up generated a trivial conflict with removal of a stale reference to Documentation/networking/net-modules.txt. Remove it from the new location instead. - fs/sysfs/dir.c: Fairly nasty conflicts with the sysfs rb-tree usage, conflicting with Eric Biederman's changes for tagged directories.
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c14
-rw-r--r--fs/sysfs/file.c56
-rw-r--r--fs/sysfs/inode.c2
3 files changed, 65 insertions, 7 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 83bb9d1f30aa..0344ee70a47c 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -403,6 +403,13 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
403{ 403{
404 struct sysfs_inode_attrs *ps_iattr; 404 struct sysfs_inode_attrs *ps_iattr;
405 405
406 if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) {
407 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
408 sysfs_ns_type(acxt->parent_sd)? "required": "invalid",
409 acxt->parent_sd->s_name, sd->s_name);
410 return -EINVAL;
411 }
412
406 if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name)) 413 if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name))
407 return -EEXIST; 414 return -EEXIST;
408 415
@@ -561,6 +568,13 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
561 struct rb_node *p = parent_sd->s_dir.name_tree.rb_node; 568 struct rb_node *p = parent_sd->s_dir.name_tree.rb_node;
562 struct sysfs_dirent *found = NULL; 569 struct sysfs_dirent *found = NULL;
563 570
571 if (!!sysfs_ns_type(parent_sd) != !!ns) {
572 WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
573 sysfs_ns_type(parent_sd)? "required": "invalid",
574 parent_sd->s_name, name);
575 return NULL;
576 }
577
564 while (p) { 578 while (p) {
565 int c; 579 int c;
566#define node rb_entry(p, struct sysfs_dirent, name_node) 580#define node rb_entry(p, struct sysfs_dirent, name_node)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 1ad8c93c1b85..d4e6080b4b20 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -466,9 +466,6 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
466 mutex_lock(&sysfs_mutex); 466 mutex_lock(&sysfs_mutex);
467 467
468 if (sd && dir) 468 if (sd && dir)
469 /* Only directories are tagged, so no need to pass
470 * a tag explicitly.
471 */
472 sd = sysfs_find_dirent(sd, NULL, dir); 469 sd = sysfs_find_dirent(sd, NULL, dir);
473 if (sd && attr) 470 if (sd && attr)
474 sd = sysfs_find_dirent(sd, NULL, attr); 471 sd = sysfs_find_dirent(sd, NULL, attr);
@@ -488,17 +485,56 @@ const struct file_operations sysfs_file_operations = {
488 .poll = sysfs_poll, 485 .poll = sysfs_poll,
489}; 486};
490 487
488int sysfs_attr_ns(struct kobject *kobj, const struct attribute *attr,
489 const void **pns)
490{
491 struct sysfs_dirent *dir_sd = kobj->sd;
492 const struct sysfs_ops *ops;
493 const void *ns = NULL;
494 int err;
495
496 err = 0;
497 if (!sysfs_ns_type(dir_sd))
498 goto out;
499
500 err = -EINVAL;
501 if (!kobj->ktype)
502 goto out;
503 ops = kobj->ktype->sysfs_ops;
504 if (!ops)
505 goto out;
506 if (!ops->namespace)
507 goto out;
508
509 err = 0;
510 ns = ops->namespace(kobj, attr);
511out:
512 if (err) {
513 WARN(1, KERN_ERR "missing sysfs namespace attribute operation for "
514 "kobject: %s\n", kobject_name(kobj));
515 }
516 *pns = ns;
517 return err;
518}
519
491int sysfs_add_file_mode(struct sysfs_dirent *dir_sd, 520int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
492 const struct attribute *attr, int type, mode_t amode) 521 const struct attribute *attr, int type, mode_t amode)
493{ 522{
494 umode_t mode = (amode & S_IALLUGO) | S_IFREG; 523 umode_t mode = (amode & S_IALLUGO) | S_IFREG;
495 struct sysfs_addrm_cxt acxt; 524 struct sysfs_addrm_cxt acxt;
496 struct sysfs_dirent *sd; 525 struct sysfs_dirent *sd;
526 const void *ns;
497 int rc; 527 int rc;
498 528
529 rc = sysfs_attr_ns(dir_sd->s_dir.kobj, attr, &ns);
530 if (rc)
531 return rc;
532
499 sd = sysfs_new_dirent(attr->name, mode, type); 533 sd = sysfs_new_dirent(attr->name, mode, type);
500 if (!sd) 534 if (!sd)
501 return -ENOMEM; 535 return -ENOMEM;
536
537 sd->s_ns = ns;
502 sd->s_attr.attr = (void *)attr; 538 sd->s_attr.attr = (void *)attr;
503 sysfs_dirent_init_lockdep(sd); 539 sysfs_dirent_init_lockdep(sd);
504 540
@@ -586,12 +622,17 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
586{ 622{
587 struct sysfs_dirent *sd; 623 struct sysfs_dirent *sd;
588 struct iattr newattrs; 624 struct iattr newattrs;
625 const void *ns;
589 int rc; 626 int rc;
590 627
628 rc = sysfs_attr_ns(kobj, attr, &ns);
629 if (rc)
630 return rc;
631
591 mutex_lock(&sysfs_mutex); 632 mutex_lock(&sysfs_mutex);
592 633
593 rc = -ENOENT; 634 rc = -ENOENT;
594 sd = sysfs_find_dirent(kobj->sd, NULL, attr->name); 635 sd = sysfs_find_dirent(kobj->sd, ns, attr->name);
595 if (!sd) 636 if (!sd)
596 goto out; 637 goto out;
597 638
@@ -616,7 +657,12 @@ EXPORT_SYMBOL_GPL(sysfs_chmod_file);
616 657
617void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr) 658void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr)
618{ 659{
619 sysfs_hash_and_remove(kobj->sd, NULL, attr->name); 660 const void *ns;
661
662 if (sysfs_attr_ns(kobj, attr, &ns))
663 return;
664
665 sysfs_hash_and_remove(kobj->sd, ns, attr->name);
620} 666}
621 667
622void sysfs_remove_files(struct kobject * kobj, const struct attribute **ptr) 668void sysfs_remove_files(struct kobject * kobj, const struct attribute **ptr)
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 1ee18c81df78..e23f28894a3a 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -324,8 +324,6 @@ int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const void *ns, const cha
324 sysfs_addrm_start(&acxt, dir_sd); 324 sysfs_addrm_start(&acxt, dir_sd);
325 325
326 sd = sysfs_find_dirent(dir_sd, ns, name); 326 sd = sysfs_find_dirent(dir_sd, ns, name);
327 if (sd && (sd->s_ns != ns))
328 sd = NULL;
329 if (sd) 327 if (sd)
330 sysfs_remove_one(&acxt, sd); 328 sysfs_remove_one(&acxt, sd);
331 329