diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-28 14:54:18 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-29 20:33:46 -0500 |
commit | fdbffaa478fc77e999cbe2ac0dcfbf609103e675 (patch) | |
tree | cb96628904017b74c53a613c3410a3bedb2526f7 /fs/sysfs/file.c | |
parent | 50b38ca086e4d9920eede98b871b971e9958d70d (diff) |
sysfs, kernfs: prepare mmap path for kernfs
We're in the process of separating out core sysfs functionality into
kernfs which will deal with sysfs_dirents directly. This patch
rearranges mmap path so that the kernfs and sysfs parts are separate.
sysfs_kf_bin_mmap() which handles the interaction with bin_attribute
mmap method is factored out of sysfs_bin_mmap(), which is renamed to
kernfs_file_mmap(). All vma ops are renamed accordingly.
sysfs_bin_mmap() is updated such that it can be used for both file
types. This will eventually allow using the same file_operations for
both file types, which is necessary to separate out kernfs.
This patch doesn't introduce any behavior changes.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 2f849e82c0eb..2e24e89bd92b 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -361,7 +361,19 @@ out_free: | |||
361 | return len; | 361 | return len; |
362 | } | 362 | } |
363 | 363 | ||
364 | static void sysfs_bin_vma_open(struct vm_area_struct *vma) | 364 | static int sysfs_kf_bin_mmap(struct sysfs_open_file *of, |
365 | struct vm_area_struct *vma) | ||
366 | { | ||
367 | struct bin_attribute *battr = of->sd->priv; | ||
368 | struct kobject *kobj = of->sd->s_parent->priv; | ||
369 | |||
370 | if (!battr->mmap) | ||
371 | return -ENODEV; | ||
372 | |||
373 | return battr->mmap(of->file, kobj, battr, vma); | ||
374 | } | ||
375 | |||
376 | static void kernfs_vma_open(struct vm_area_struct *vma) | ||
365 | { | 377 | { |
366 | struct file *file = vma->vm_file; | 378 | struct file *file = vma->vm_file; |
367 | struct sysfs_open_file *of = sysfs_of(file); | 379 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -378,7 +390,7 @@ static void sysfs_bin_vma_open(struct vm_area_struct *vma) | |||
378 | sysfs_put_active(of->sd); | 390 | sysfs_put_active(of->sd); |
379 | } | 391 | } |
380 | 392 | ||
381 | static int sysfs_bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 393 | static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
382 | { | 394 | { |
383 | struct file *file = vma->vm_file; | 395 | struct file *file = vma->vm_file; |
384 | struct sysfs_open_file *of = sysfs_of(file); | 396 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -398,8 +410,8 @@ static int sysfs_bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
398 | return ret; | 410 | return ret; |
399 | } | 411 | } |
400 | 412 | ||
401 | static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma, | 413 | static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma, |
402 | struct vm_fault *vmf) | 414 | struct vm_fault *vmf) |
403 | { | 415 | { |
404 | struct file *file = vma->vm_file; | 416 | struct file *file = vma->vm_file; |
405 | struct sysfs_open_file *of = sysfs_of(file); | 417 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -421,8 +433,8 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma, | |||
421 | return ret; | 433 | return ret; |
422 | } | 434 | } |
423 | 435 | ||
424 | static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr, | 436 | static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr, |
425 | void *buf, int len, int write) | 437 | void *buf, int len, int write) |
426 | { | 438 | { |
427 | struct file *file = vma->vm_file; | 439 | struct file *file = vma->vm_file; |
428 | struct sysfs_open_file *of = sysfs_of(file); | 440 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -443,8 +455,8 @@ static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr, | |||
443 | } | 455 | } |
444 | 456 | ||
445 | #ifdef CONFIG_NUMA | 457 | #ifdef CONFIG_NUMA |
446 | static int sysfs_bin_set_policy(struct vm_area_struct *vma, | 458 | static int kernfs_vma_set_policy(struct vm_area_struct *vma, |
447 | struct mempolicy *new) | 459 | struct mempolicy *new) |
448 | { | 460 | { |
449 | struct file *file = vma->vm_file; | 461 | struct file *file = vma->vm_file; |
450 | struct sysfs_open_file *of = sysfs_of(file); | 462 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -464,8 +476,8 @@ static int sysfs_bin_set_policy(struct vm_area_struct *vma, | |||
464 | return ret; | 476 | return ret; |
465 | } | 477 | } |
466 | 478 | ||
467 | static struct mempolicy *sysfs_bin_get_policy(struct vm_area_struct *vma, | 479 | static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma, |
468 | unsigned long addr) | 480 | unsigned long addr) |
469 | { | 481 | { |
470 | struct file *file = vma->vm_file; | 482 | struct file *file = vma->vm_file; |
471 | struct sysfs_open_file *of = sysfs_of(file); | 483 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -485,8 +497,9 @@ static struct mempolicy *sysfs_bin_get_policy(struct vm_area_struct *vma, | |||
485 | return pol; | 497 | return pol; |
486 | } | 498 | } |
487 | 499 | ||
488 | static int sysfs_bin_migrate(struct vm_area_struct *vma, const nodemask_t *from, | 500 | static int kernfs_vma_migrate(struct vm_area_struct *vma, |
489 | const nodemask_t *to, unsigned long flags) | 501 | const nodemask_t *from, const nodemask_t *to, |
502 | unsigned long flags) | ||
490 | { | 503 | { |
491 | struct file *file = vma->vm_file; | 504 | struct file *file = vma->vm_file; |
492 | struct sysfs_open_file *of = sysfs_of(file); | 505 | struct sysfs_open_file *of = sysfs_of(file); |
@@ -507,36 +520,31 @@ static int sysfs_bin_migrate(struct vm_area_struct *vma, const nodemask_t *from, | |||
507 | } | 520 | } |
508 | #endif | 521 | #endif |
509 | 522 | ||
510 | static const struct vm_operations_struct sysfs_bin_vm_ops = { | 523 | static const struct vm_operations_struct kernfs_vm_ops = { |
511 | .open = sysfs_bin_vma_open, | 524 | .open = kernfs_vma_open, |
512 | .fault = sysfs_bin_fault, | 525 | .fault = kernfs_vma_fault, |
513 | .page_mkwrite = sysfs_bin_page_mkwrite, | 526 | .page_mkwrite = kernfs_vma_page_mkwrite, |
514 | .access = sysfs_bin_access, | 527 | .access = kernfs_vma_access, |
515 | #ifdef CONFIG_NUMA | 528 | #ifdef CONFIG_NUMA |
516 | .set_policy = sysfs_bin_set_policy, | 529 | .set_policy = kernfs_vma_set_policy, |
517 | .get_policy = sysfs_bin_get_policy, | 530 | .get_policy = kernfs_vma_get_policy, |
518 | .migrate = sysfs_bin_migrate, | 531 | .migrate = kernfs_vma_migrate, |
519 | #endif | 532 | #endif |
520 | }; | 533 | }; |
521 | 534 | ||
522 | static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma) | 535 | static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma) |
523 | { | 536 | { |
524 | struct sysfs_open_file *of = sysfs_of(file); | 537 | struct sysfs_open_file *of = sysfs_of(file); |
525 | struct bin_attribute *battr = of->sd->priv; | ||
526 | struct kobject *kobj = of->sd->s_parent->priv; | ||
527 | int rc; | 538 | int rc; |
528 | 539 | ||
529 | mutex_lock(&of->mutex); | 540 | mutex_lock(&of->mutex); |
530 | 541 | ||
531 | /* need of->sd for battr, its parent for kobj */ | ||
532 | rc = -ENODEV; | 542 | rc = -ENODEV; |
533 | if (!sysfs_get_active(of->sd)) | 543 | if (!sysfs_get_active(of->sd)) |
534 | goto out_unlock; | 544 | goto out_unlock; |
535 | 545 | ||
536 | if (!battr->mmap) | 546 | if (sysfs_is_bin(of->sd)) |
537 | goto out_put; | 547 | rc = sysfs_kf_bin_mmap(of, vma); |
538 | |||
539 | rc = battr->mmap(file, kobj, battr, vma); | ||
540 | if (rc) | 548 | if (rc) |
541 | goto out_put; | 549 | goto out_put; |
542 | 550 | ||
@@ -563,7 +571,7 @@ static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma) | |||
563 | rc = 0; | 571 | rc = 0; |
564 | of->mmapped = 1; | 572 | of->mmapped = 1; |
565 | of->vm_ops = vma->vm_ops; | 573 | of->vm_ops = vma->vm_ops; |
566 | vma->vm_ops = &sysfs_bin_vm_ops; | 574 | vma->vm_ops = &kernfs_vm_ops; |
567 | out_put: | 575 | out_put: |
568 | sysfs_put_active(of->sd); | 576 | sysfs_put_active(of->sd); |
569 | out_unlock: | 577 | out_unlock: |
@@ -877,6 +885,7 @@ const struct file_operations sysfs_file_operations = { | |||
877 | .read = kernfs_file_read, | 885 | .read = kernfs_file_read, |
878 | .write = kernfs_file_write, | 886 | .write = kernfs_file_write, |
879 | .llseek = generic_file_llseek, | 887 | .llseek = generic_file_llseek, |
888 | .mmap = kernfs_file_mmap, | ||
880 | .open = sysfs_open_file, | 889 | .open = sysfs_open_file, |
881 | .release = sysfs_release, | 890 | .release = sysfs_release, |
882 | .poll = sysfs_poll, | 891 | .poll = sysfs_poll, |
@@ -886,7 +895,7 @@ const struct file_operations sysfs_bin_operations = { | |||
886 | .read = kernfs_file_read, | 895 | .read = kernfs_file_read, |
887 | .write = kernfs_file_write, | 896 | .write = kernfs_file_write, |
888 | .llseek = generic_file_llseek, | 897 | .llseek = generic_file_llseek, |
889 | .mmap = sysfs_bin_mmap, | 898 | .mmap = kernfs_file_mmap, |
890 | .open = sysfs_open_file, | 899 | .open = sysfs_open_file, |
891 | .release = sysfs_release, | 900 | .release = sysfs_release, |
892 | .poll = sysfs_poll, | 901 | .poll = sysfs_poll, |