Commit 6cf32f7
Support RENAME_EXCHANGE in tmpfs and overlayfs
renameat2(2) support was added in 2c1c4a5 ("Implement renameat2."), but only for the gofer filesystem; tmpfs and overlayfs still return EINVAL for RENAME_EXCHANGE.
Implement RENAME_EXCHANGE in tmpfs by swapping the two dentries between their parent directories. When the exchanged files differ in type, the parents' link counts (for "..") and the exchanged directory's reference on its parent are transferred.
Implement RENAME_EXCHANGE in overlayfs by copying up the destination file (and its descendants, if it is a directory) in addition to the source, and then exchanging both files on the upper layer. Unlike a regular rename, no whiteout is created at the source location, since both locations remain occupied. Exchanged directories are marked opaque at their new locations to prevent merging with lower layer directories there.
RENAME_EXCHANGE permits the two files to differ in type and does not require a directory being exchanged to be empty, but exchanging a file with an ancestor directory must fail with EINVAL; see Linux's fs/namei.c:__start_renaming(). The gofer filesystem previously required both files to have the same type; lift that restriction, and update parent link counts when files of different types are exchanged across directories.
The RENAME_EXCHANGE syscall tests no longer accept EINVAL (except on FUSE, which does not support the flag), and new tests cover mixed-type exchanges and exchanges with ancestor directories.
Fixes #7895
FUTURE_COPYBARA_INTEGRATE_REVIEW=#14221 from ayushr2:rename 26ca2a3
PiperOrigin-RevId: 9707919911 parent 917062d commit 6cf32f7
4 files changed
Lines changed: 346 additions & 116 deletions
File tree
- pkg/sentry/fsimpl
- gofer
- overlay
- tmpfs
- test/syscalls/linux
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1440 | 1440 | | |
1441 | 1441 | | |
1442 | 1442 | | |
| 1443 | + | |
1443 | 1444 | | |
1444 | 1445 | | |
1445 | 1446 | | |
| |||
1500 | 1501 | | |
1501 | 1502 | | |
1502 | 1503 | | |
1503 | | - | |
| 1504 | + | |
1504 | 1505 | | |
1505 | 1506 | | |
1506 | 1507 | | |
| |||
1528 | 1529 | | |
1529 | 1530 | | |
1530 | 1531 | | |
1531 | | - | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
1532 | 1552 | | |
1533 | 1553 | | |
1534 | 1554 | | |
| |||
1541 | 1561 | | |
1542 | 1562 | | |
1543 | 1563 | | |
1544 | | - | |
| 1564 | + | |
1545 | 1565 | | |
1546 | 1566 | | |
1547 | 1567 | | |
| |||
1562 | 1582 | | |
1563 | 1583 | | |
1564 | 1584 | | |
1565 | | - | |
| 1585 | + | |
1566 | 1586 | | |
1567 | 1587 | | |
1568 | 1588 | | |
| |||
1583 | 1603 | | |
1584 | 1604 | | |
1585 | 1605 | | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
| 1606 | + | |
| 1607 | + | |
1591 | 1608 | | |
1592 | 1609 | | |
1593 | 1610 | | |
| |||
1616 | 1633 | | |
1617 | 1634 | | |
1618 | 1635 | | |
1619 | | - | |
1620 | | - | |
1621 | | - | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
1622 | 1658 | | |
1623 | 1659 | | |
1624 | 1660 | | |
1625 | 1661 | | |
1626 | | - | |
1627 | | - | |
1628 | | - | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
1632 | | - | |
1633 | | - | |
1634 | | - | |
1635 | | - | |
1636 | | - | |
1637 | | - | |
1638 | | - | |
1639 | | - | |
1640 | | - | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | | - | |
1645 | | - | |
1646 | | - | |
1647 | | - | |
1648 | | - | |
1649 | | - | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
1655 | | - | |
1656 | | - | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
1657 | 1694 | | |
1658 | | - | |
1659 | | - | |
1660 | | - | |
1661 | | - | |
1662 | | - | |
1663 | | - | |
1664 | | - | |
1665 | | - | |
1666 | | - | |
1667 | | - | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
1668 | 1704 | | |
1669 | | - | |
1670 | | - | |
1671 | | - | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
1676 | 1712 | | |
1677 | | - | |
1678 | 1713 | | |
| 1714 | + | |
1679 | 1715 | | |
1680 | 1716 | | |
1681 | 1717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1090 | 1090 | | |
1091 | 1091 | | |
1092 | 1092 | | |
1093 | | - | |
| 1093 | + | |
1094 | 1094 | | |
1095 | 1095 | | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
1096 | 1100 | | |
1097 | 1101 | | |
1098 | 1102 | | |
| |||
1142 | 1146 | | |
1143 | 1147 | | |
1144 | 1148 | | |
1145 | | - | |
| 1149 | + | |
1146 | 1150 | | |
1147 | 1151 | | |
1148 | 1152 | | |
| |||
1175 | 1179 | | |
1176 | 1180 | | |
1177 | 1181 | | |
1178 | | - | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
1179 | 1202 | | |
1180 | 1203 | | |
1181 | 1204 | | |
| |||
1193 | 1216 | | |
1194 | 1217 | | |
1195 | 1218 | | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1196 | 1222 | | |
1197 | 1223 | | |
1198 | 1224 | | |
| |||
1216 | 1242 | | |
1217 | 1243 | | |
1218 | 1244 | | |
1219 | | - | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
1223 | 1263 | | |
1224 | 1264 | | |
1225 | 1265 | | |
| |||
1255 | 1295 | | |
1256 | 1296 | | |
1257 | 1297 | | |
1258 | | - | |
| 1298 | + | |
1259 | 1299 | | |
1260 | 1300 | | |
1261 | 1301 | | |
| |||
1303 | 1343 | | |
1304 | 1344 | | |
1305 | 1345 | | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
1306 | 1384 | | |
1307 | 1385 | | |
1308 | 1386 | | |
| |||
0 commit comments