Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[readdir] convert configfs

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 52018855 3903b38c

+50 -68
+50 -68
fs/configfs/dir.c
··· 1532 1532 return (sd->s_mode >> 12) & 15; 1533 1533 } 1534 1534 1535 - static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir) 1535 + static int configfs_readdir(struct file *file, struct dir_context *ctx) 1536 1536 { 1537 - struct dentry *dentry = filp->f_path.dentry; 1537 + struct dentry *dentry = file->f_path.dentry; 1538 1538 struct super_block *sb = dentry->d_sb; 1539 1539 struct configfs_dirent * parent_sd = dentry->d_fsdata; 1540 - struct configfs_dirent *cursor = filp->private_data; 1540 + struct configfs_dirent *cursor = file->private_data; 1541 1541 struct list_head *p, *q = &cursor->s_sibling; 1542 1542 ino_t ino = 0; 1543 - int i = filp->f_pos; 1544 1543 1545 - switch (i) { 1546 - case 0: 1547 - ino = dentry->d_inode->i_ino; 1548 - if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0) 1549 - break; 1550 - filp->f_pos++; 1551 - i++; 1552 - /* fallthrough */ 1553 - case 1: 1554 - ino = parent_ino(dentry); 1555 - if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0) 1556 - break; 1557 - filp->f_pos++; 1558 - i++; 1559 - /* fallthrough */ 1560 - default: 1561 - if (filp->f_pos == 2) { 1562 - spin_lock(&configfs_dirent_lock); 1563 - list_move(q, &parent_sd->s_children); 1564 - spin_unlock(&configfs_dirent_lock); 1565 - } 1566 - for (p=q->next; p!= &parent_sd->s_children; p=p->next) { 1567 - struct configfs_dirent *next; 1568 - const char * name; 1569 - int len; 1570 - struct inode *inode = NULL; 1544 + if (!dir_emit_dots(file, ctx)) 1545 + return 0; 1546 + if (ctx->pos == 2) { 1547 + spin_lock(&configfs_dirent_lock); 1548 + list_move(q, &parent_sd->s_children); 1549 + spin_unlock(&configfs_dirent_lock); 1550 + } 1551 + for (p = q->next; p != &parent_sd->s_children; p = p->next) { 1552 + struct configfs_dirent *next; 1553 + const char *name; 1554 + int len; 1555 + struct inode *inode = NULL; 1571 1556 1572 - next = list_entry(p, struct configfs_dirent, 1573 - s_sibling); 1574 - if (!next->s_element) 1575 - continue; 1557 + next = list_entry(p, struct configfs_dirent, s_sibling); 1558 + if (!next->s_element) 1559 + continue; 1576 1560 1577 - name = configfs_get_name(next); 1578 - len = strlen(name); 1561 + name = configfs_get_name(next); 1562 + len = strlen(name); 1579 1563 1580 - /* 1581 - * We'll have a dentry and an inode for 1582 - * PINNED items and for open attribute 1583 - * files. We lock here to prevent a race 1584 - * with configfs_d_iput() clearing 1585 - * s_dentry before calling iput(). 1586 - * 1587 - * Why do we go to the trouble? If 1588 - * someone has an attribute file open, 1589 - * the inode number should match until 1590 - * they close it. Beyond that, we don't 1591 - * care. 1592 - */ 1593 - spin_lock(&configfs_dirent_lock); 1594 - dentry = next->s_dentry; 1595 - if (dentry) 1596 - inode = dentry->d_inode; 1597 - if (inode) 1598 - ino = inode->i_ino; 1599 - spin_unlock(&configfs_dirent_lock); 1600 - if (!inode) 1601 - ino = iunique(sb, 2); 1564 + /* 1565 + * We'll have a dentry and an inode for 1566 + * PINNED items and for open attribute 1567 + * files. We lock here to prevent a race 1568 + * with configfs_d_iput() clearing 1569 + * s_dentry before calling iput(). 1570 + * 1571 + * Why do we go to the trouble? If 1572 + * someone has an attribute file open, 1573 + * the inode number should match until 1574 + * they close it. Beyond that, we don't 1575 + * care. 1576 + */ 1577 + spin_lock(&configfs_dirent_lock); 1578 + dentry = next->s_dentry; 1579 + if (dentry) 1580 + inode = dentry->d_inode; 1581 + if (inode) 1582 + ino = inode->i_ino; 1583 + spin_unlock(&configfs_dirent_lock); 1584 + if (!inode) 1585 + ino = iunique(sb, 2); 1602 1586 1603 - if (filldir(dirent, name, len, filp->f_pos, ino, 1604 - dt_type(next)) < 0) 1605 - return 0; 1587 + if (!dir_emit(ctx, name, len, ino, dt_type(next))) 1588 + return 0; 1606 1589 1607 - spin_lock(&configfs_dirent_lock); 1608 - list_move(q, p); 1609 - spin_unlock(&configfs_dirent_lock); 1610 - p = q; 1611 - filp->f_pos++; 1612 - } 1590 + spin_lock(&configfs_dirent_lock); 1591 + list_move(q, p); 1592 + spin_unlock(&configfs_dirent_lock); 1593 + p = q; 1594 + ctx->pos++; 1613 1595 } 1614 1596 return 0; 1615 1597 } ··· 1643 1661 .release = configfs_dir_close, 1644 1662 .llseek = configfs_dir_lseek, 1645 1663 .read = generic_read_dir, 1646 - .readdir = configfs_readdir, 1664 + .iterate = configfs_readdir, 1647 1665 }; 1648 1666 1649 1667 int configfs_register_subsystem(struct configfs_subsystem *subsys)