diff options
Diffstat (limited to 'debian/patches')
34 files changed, 6288 insertions, 0 deletions
diff --git a/debian/patches/console_ignore_bdf_err.patch b/debian/patches/console_ignore_bdf_err.patch new file mode 100644 index 00000000..c3ea30cb --- /dev/null +++ b/debian/patches/console_ignore_bdf_err.patch @@ -0,0 +1,17 @@ +reduce-font overestimates the number of characters in the font. + +diff --git a/console-client/bdf.c b/console-client/bdf.c +index 30501f4..ee8aa30 100644 +--- a/console-client/bdf.c ++++ b/console-client/bdf.c +@@ -415,8 +415,10 @@ bdf_read (FILE *filep, bdf_font_t *font, int *linecount) + glyphs. */ + if (!strcmp (line, "ENDFONT")) + { ++ /* + if (parser.glyphs != bdf->glyphs_count) + err = BDF_COUNT_MISMATCH; ++ */ + done = 1; + } + else diff --git a/debian/patches/console_utf-8.patch b/debian/patches/console_utf-8.patch new file mode 100644 index 00000000..663e21bd --- /dev/null +++ b/debian/patches/console_utf-8.patch @@ -0,0 +1,19 @@ +2006-08-26 Michael Banck <mbanck@debian.org> + + * console.c (DEFAULT_ENCODING): Set to UTF-8. + +--- + console/console.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/console/console.c ++++ b/console/console.c +@@ -58,7 +58,7 @@ int netfs_maxsymlinks = 16; /* Arbitrary + /* Handy source of time. */ + volatile struct mapped_time_value *console_maptime; + +-#define DEFAULT_ENCODING "ISO-8859-1" ++#define DEFAULT_ENCODING "UTF-8" + #define DEFAULT_INTENSITY CONS_ATTR_INTENSITY_NORMAL + #define DEFAULT_UNDERLINED 0 + #define DEFAULT_BLINKING 0 diff --git a/debian/patches/diskfs_no_inherit_dir_group.patch b/debian/patches/diskfs_no_inherit_dir_group.patch new file mode 100644 index 00000000..8d17f3e0 --- /dev/null +++ b/debian/patches/diskfs_no_inherit_dir_group.patch @@ -0,0 +1,29 @@ +Follow POSIX rules for gid of new nodes. +--- + opts-common.c | 2 +- + libdiskfs/init-init.c | 3 +++ + 2 file changed, 4 insertion(+), 1 deletion(-) + +--- a/libdiskfs/init-init.c ++++ b/libdiskfs/init-init.c +@@ -57,6 +57,9 @@ diskfs_init_diskfs (void) + { + error_t err; + ++ /* See `node-create.c'. */ ++ _diskfs_no_inherit_dir_group = 1; ++ + if (diskfs_boot_filesystem ()) + /* This is a boot filesystem, we have to do some things specially. */ + { +--- a/libdiskfs/opts-common.c ++++ b/libdiskfs/opts-common.c +@@ -52,7 +52,7 @@ const struct argp_option diskfs_common_options[] = + {"nogrpid", 0, 0, OPTION_ALIAS | OPTION_HIDDEN}, + {"sysvgroups", 0, 0, OPTION_ALIAS | OPTION_HIDDEN}, + {"inherit-dir-group", OPT_INHERIT_DIR_GROUP, 0, 0, +- "Create new nodes with gid of parent dir (default)"}, ++ "Create new nodes with gid of parent dir"}, + {"grpid", 0, 0, OPTION_ALIAS | OPTION_HIDDEN}, + {"bsdgroups", 0, 0, OPTION_ALIAS | OPTION_HIDDEN}, + {0, 0} diff --git a/debian/patches/ext2fs_large_stores.patch b/debian/patches/ext2fs_large_stores.patch new file mode 100644 index 00000000..0855f760 --- /dev/null +++ b/debian/patches/ext2fs_large_stores.patch @@ -0,0 +1,2223 @@ +Support for >2GB volumes +--- + console/pager.c | 10 + ext2fs/balloc.c | 57 +++-- + ext2fs/ext2_fs.h | 3 + ext2fs/ext2fs.c | 8 + ext2fs/ext2fs.h | 145 +++++++++++-- + ext2fs/getblk.c | 31 +- + ext2fs/hyper.c | 34 ++- + ext2fs/ialloc.c | 41 +++ + ext2fs/inode.c | 58 +++-- + ext2fs/pager.c | 497 +++++++++++++++++++++++++++++++++++++++++++---- + ext2fs/pokel.c | 41 +++ + ext2fs/truncate.c | 11 - + fatfs/pager.c | 11 - + isofs/pager.c | 12 - + libdiskfs/disk-pager.c | 6 + libdiskfs/diskfs-pager.h | 3 + libpager/data-request.c | 17 - + libpager/data-return.c | 78 +++++-- + libpager/pager-create.c | 4 + libpager/pager.h | 29 ++ + libpager/priv.h | 1 + storeio/pager.c | 9 + tmpfs/pager-stubs.c | 8 + ufs/pager.c | 11 - + 24 files changed, 940 insertions(+), 185 deletions(-) + +--- a/console/pager.c ++++ b/console/pager.c +@@ -94,6 +94,14 @@ pager_unlock_page (struct user_pager_inf + } + + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ assert (!"unrequested notification on eviction"); ++} ++ ++ + /* Tell how big the file is. */ + error_t + pager_report_extent (struct user_pager_info *upi, +@@ -159,7 +167,7 @@ user_pager_create (struct user_pager *us + + /* XXX Are the values 1 and MEMORY_OBJECT_COPY_DELAY correct? */ + user_pager->pager = pager_create (upi, pager_bucket, +- 1, MEMORY_OBJECT_COPY_DELAY); ++ 1, MEMORY_OBJECT_COPY_DELAY, 0); + if (!user_pager->pager) + { + free (upi); +--- a/ext2fs/balloc.c ++++ b/ext2fs/balloc.c +@@ -92,7 +92,7 @@ ext2_free_blocks (block_t block, unsigne + block, count); + } + gdp = group_desc (block_group); +- bh = bptr (gdp->bg_block_bitmap); ++ bh = disk_cache_block_ref (gdp->bg_block_bitmap); + + if (in_range (gdp->bg_block_bitmap, block, gcount) || + in_range (gdp->bg_inode_bitmap, block, gcount) || +@@ -114,6 +114,7 @@ ext2_free_blocks (block_t block, unsigne + } + + record_global_poke (bh); ++ disk_cache_block_ref_ptr (gdp); + record_global_poke (gdp); + + block += gcount; +@@ -139,7 +140,7 @@ ext2_new_block (block_t goal, + block_t prealloc_goal, + block_t *prealloc_count, block_t *prealloc_block) + { +- char *bh; ++ char *bh = 0; + char *p, *r; + int i, j, k, tmp; + unsigned long lmap; +@@ -164,9 +165,10 @@ ext2_new_block (block_t goal, + + ext2_debug ("goal=%u", goal); + +-repeat: ++ repeat: ++ assert (! bh); + /* +- * First, test whether the goal block is free. ++ * First, test whether the goal block is free. + */ + if (goal < sblock->s_first_data_block || goal >= sblock->s_blocks_count) + goal = sblock->s_first_data_block; +@@ -179,7 +181,7 @@ repeat: + if (j) + goal_attempts++; + #endif +- bh = bptr (gdp->bg_block_bitmap); ++ bh = disk_cache_block_ref (gdp->bg_block_bitmap); + + ext2_debug ("goal is at %d:%d", i, j); + +@@ -194,8 +196,8 @@ repeat: + if (j) + { + /* +- * The goal was occupied; search forward for a free +- * block within the next 32 blocks ++ * The goal was occupied; search forward for a free ++ * block within the next 32 blocks + */ + lmap = ((((unsigned long *) bh)[j >> 5]) >> + ((j & 31) + 1)); +@@ -242,13 +244,16 @@ repeat: + j = k; + goto got_block; + } ++ ++ disk_cache_block_deref (bh); ++ bh = 0; + } + + ext2_debug ("bit not found in block group %d", i); + + /* +- * Now search the rest of the groups. We assume that +- * i and gdp correctly point to the last group visited. ++ * Now search the rest of the groups. We assume that ++ * i and gdp correctly point to the last group visited. + */ + for (k = 0; k < groups_count; k++) + { +@@ -264,7 +269,8 @@ repeat: + spin_unlock (&global_lock); + return 0; + } +- bh = bptr (gdp->bg_block_bitmap); ++ assert (! bh); ++ bh = disk_cache_block_ref (gdp->bg_block_bitmap); + r = memscan (bh, 0, sblock->s_blocks_per_group >> 3); + j = (r - bh) << 3; + if (j < sblock->s_blocks_per_group) +@@ -274,21 +280,25 @@ repeat: + sblock->s_blocks_per_group); + if (j >= sblock->s_blocks_per_group) + { ++ disk_cache_block_deref (bh); ++ bh = 0; + ext2_error ("free blocks count corrupted for block group %d", i); + spin_unlock (&global_lock); + return 0; + } + +-search_back: ++ search_back: ++ assert (bh); + /* +- * We have succeeded in finding a free byte in the block +- * bitmap. Now search backwards up to 7 bits to find the +- * start of this group of free blocks. ++ * We have succeeded in finding a free byte in the block ++ * bitmap. Now search backwards up to 7 bits to find the ++ * start of this group of free blocks. + */ + for (k = 0; k < 7 && j > 0 && !test_bit (j - 1, bh); k++, j--); + +-got_block: +- ++ got_block: ++ assert (bh); ++ + ext2_debug ("using block group %d (%d)", i, gdp->bg_free_blocks_count); + + tmp = j + i * sblock->s_blocks_per_group + sblock->s_first_data_block; +@@ -301,6 +311,8 @@ got_block: + if (set_bit (j, bh)) + { + ext2_warning ("bit already set for block %d", j); ++ disk_cache_block_deref (bh); ++ bh = 0; + goto repeat; + } + +@@ -317,7 +329,7 @@ got_block: + ext2_debug ("found bit %d", j); + + /* +- * Do block preallocation now if required. ++ * Do block preallocation now if required. + */ + #ifdef EXT2_PREALLOCATE + if (prealloc_goal) +@@ -348,6 +360,7 @@ got_block: + j = tmp; + + record_global_poke (bh); ++ bh = 0; + + if (j >= sblock->s_blocks_count) + { +@@ -360,12 +373,14 @@ got_block: + j, goal_hits, goal_attempts); + + gdp->bg_free_blocks_count--; ++ disk_cache_block_ref_ptr (gdp); + record_global_poke (gdp); + + sblock->s_free_blocks_count--; + sblock_dirty = 1; + + sync_out: ++ assert (! bh); + spin_unlock (&global_lock); + alloc_sync (0); + +@@ -387,9 +402,12 @@ ext2_count_free_blocks () + gdp = NULL; + for (i = 0; i < groups_count; i++) + { ++ void *bh; + gdp = group_desc (i); + desc_count += gdp->bg_free_blocks_count; +- x = count_free (bptr (gdp->bg_block_bitmap), block_size); ++ bh = disk_cache_block_ref (gdp->bg_block_bitmap); ++ x = count_free (bh, block_size); ++ disk_cache_block_deref (bh); + printf ("group %d: stored = %d, counted = %lu", + i, gdp->bg_free_blocks_count, x); + bitmap_count += x; +@@ -450,7 +468,7 @@ ext2_check_blocks_bitmap () + + gdp = group_desc (i); + desc_count += gdp->bg_free_blocks_count; +- bh = bptr (gdp->bg_block_bitmap); ++ bh = disk_cache_block_ref (gdp->bg_block_bitmap); + + if (!EXT2_HAS_RO_COMPAT_FEATURE (sblock, + EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) +@@ -476,6 +494,7 @@ ext2_check_blocks_bitmap () + ext2_error ("block #%d of the inode table in group %d is marked free", j, i); + + x = count_free (bh, block_size); ++ disk_cache_block_deref (bh); + if (gdp->bg_free_blocks_count != x) + ext2_error ("wrong free blocks count for group %d," + " stored = %d, counted = %lu", +--- a/ext2fs/ext2_fs.h ++++ b/ext2fs/ext2_fs.h +@@ -25,7 +25,8 @@ + /* + * Define EXT2FS_DEBUG to produce debug messages + */ +-#undef EXT2FS_DEBUG ++/* #undef EXT2FS_DEBUG */ ++#define EXT2FS_DEBUG + + /* + * Define EXT2_PREALLOCATE to preallocate data blocks for expanding files +--- a/ext2fs/ext2fs.c ++++ b/ext2fs/ext2fs.c +@@ -106,7 +106,7 @@ parse_opt (int key, char *arg, struct ar + if (values == 0) + return ENOMEM; + state->hook = values; +- bzero (values, sizeof *values); ++ memset (values, 0, sizeof *values); + values->sb_block = SBLOCK_BLOCK; + break; + +@@ -181,9 +181,9 @@ main (int argc, char **argv) + /* Map the entire disk. */ + create_disk_pager (); + +- pokel_init (&global_pokel, diskfs_disk_pager, disk_image); ++ pokel_init (&global_pokel, diskfs_disk_pager, disk_cache); + +- get_hypermetadata(); ++ map_hypermetadata (); + + inode_init (); + +@@ -211,6 +211,8 @@ diskfs_reload_global_state () + { + pokel_flush (&global_pokel); + pager_flush (diskfs_disk_pager, 1); ++ sblock = 0; + get_hypermetadata (); ++ map_hypermetadata (); + return 0; + } +--- a/ext2fs/ext2fs.h ++++ b/ext2fs/ext2fs.h +@@ -23,7 +23,9 @@ + #include <hurd/pager.h> + #include <hurd/fshelp.h> + #include <hurd/iohelp.h> ++#include <hurd/store.h> + #include <hurd/diskfs.h> ++#include <hurd/ihash.h> + #include <assert.h> + #include <rwlock.h> + #include <sys/mman.h> +@@ -186,6 +188,8 @@ struct user_pager_info + /* ---------------------------------------------------------------- */ + /* pager.c */ + ++#define DISK_CACHE_BLOCKS 65536 ++ + #include <hurd/diskfs-pager.h> + + /* Set up the disk pager. */ +@@ -209,10 +213,54 @@ extern struct store *store; + /* What the user specified. */ + extern struct store_parsed *store_parsed; + +-/* Mapped image of the disk. */ +-extern void *disk_image; ++/* Mapped image of cached blocks of the disk. */ ++extern void *disk_cache; ++extern store_offset_t disk_cache_size; ++extern int disk_cache_blocks; ++ ++#define DC_INCORE 0x01 /* Not in core. */ ++#define DC_UNTOUCHED 0x02 /* Not touched by disk_pager_read_paged ++ or disk_cache_block_ref. */ ++#define DC_FIXED 0x04 /* Must not be re-associated. */ ++ ++/* Flags that forbid re-association of page. DC_UNTOUCHED is included ++ because this flag is used only when page is already to be ++ re-associated, so it's not good candidate for another ++ remapping. */ ++#define DC_DONT_REUSE (DC_INCORE | DC_UNTOUCHED | DC_FIXED) ++ ++#define DC_NO_BLOCK ((block_t) -1L) ++ ++#ifndef NDEBUG ++#define DISK_CACHE_LAST_READ_XOR 0xDEADBEEF ++#endif + +-/* Our in-core copy of the super-block (pointer into the disk_image). */ ++/* Disk cache blocks' meta info. */ ++struct disk_cache_info ++{ ++ block_t block; ++ uint16_t flags; ++ uint16_t ref_count; ++#ifndef NDEBUG ++ block_t last_read, last_read_xor; ++#endif ++}; ++ ++/* block num --> pointer to in-memory block */ ++extern hurd_ihash_t disk_cache_bptr; ++/* Metadata about cached block. */ ++extern struct disk_cache_info *disk_cache_info; ++/* Lock for these mappings */ ++extern struct mutex disk_cache_lock; ++/* Fired when a re-association is done. */ ++extern struct condition disk_cache_reassociation; ++ ++void *disk_cache_block_ref (block_t block); ++void disk_cache_block_ref_ptr (void *ptr); ++void disk_cache_block_deref (void *ptr); ++int disk_cache_block_is_ref (block_t block); ++ ++/* Our in-core copy of the super-block (pointer into the disk_cache). */ + struct ext2_super_block *sblock; + /* True if sblock has been modified. */ + int sblock_dirty; +@@ -242,6 +290,9 @@ vm_address_t zeroblock; + + /* Get the superblock from the disk, & setup various global info from it. */ + void get_hypermetadata (); ++ ++/* Map `sblock' and `group_desc_image' pointers to disk cache. */ ++void map_hypermetadata (); + + /* ---------------------------------------------------------------- */ + /* Random stuff calculated from the super block. */ +@@ -265,21 +316,51 @@ spin_lock_t generation_lock; + unsigned long next_generation; + + /* ---------------------------------------------------------------- */ +-/* Functions for looking inside disk_image */ ++/* Functions for looking inside disk_cache */ + +-#define trunc_block(offs) (((offs) >> log2_block_size) << log2_block_size) ++#define trunc_block(offs) \ ++ ((off_t) ((offs) >> log2_block_size) << log2_block_size) + #define round_block(offs) \ +- ((((offs) + block_size - 1) >> log2_block_size) << log2_block_size) ++ ((off_t) (((offs) + block_size - 1) >> log2_block_size) << log2_block_size) + + /* block num --> byte offset on disk */ +-#define boffs(block) ((block) << log2_block_size) ++#define boffs(block) ((off_t) (block) << log2_block_size) + /* byte offset on disk --> block num */ + #define boffs_block(offs) ((offs) >> log2_block_size) + ++/* pointer to in-memory block -> index in disk_cache_info */ ++#define bptr_index(ptr) (((char *)ptr - (char *)disk_cache) >> log2_block_size) ++ + /* byte offset on disk --> pointer to in-memory block */ +-#define boffs_ptr(offs) (((char *)disk_image) + (offs)) ++EXT2FS_EI char * ++boffs_ptr (off_t offset) ++{ ++ block_t block = boffs_block (offset); ++ mutex_lock (&disk_cache_lock); ++ char *ptr = hurd_ihash_find (disk_cache_bptr, block); ++ mutex_unlock (&disk_cache_lock); ++ assert (ptr); ++ ptr += offset % block_size; ++ ext2_debug ("(%Ld) = %p", offset, ptr); ++ return ptr; ++} ++ + /* pointer to in-memory block --> byte offset on disk */ +-#define bptr_offs(ptr) ((char *)(ptr) - ((char *)disk_image)) ++EXT2FS_EI off_t ++bptr_offs (void *ptr) ++{ ++ vm_offset_t mem_offset = (char *)ptr - (char *)disk_cache; ++ off_t offset; ++ assert (mem_offset < disk_cache_size); ++ mutex_lock (&disk_cache_lock); ++ offset = (off_t) disk_cache_info[boffs_block (mem_offset)].block ++ << log2_block_size; ++ assert (offset || mem_offset < block_size); ++ offset += mem_offset % block_size; ++ mutex_unlock (&disk_cache_lock); ++ ext2_debug ("(%p) = %Ld", ptr, offset); ++ return offset; ++} + + /* block num --> pointer to in-memory block */ + #define bptr(block) boffs_ptr(boffs(block)) +@@ -296,14 +377,24 @@ struct ext2_group_desc *group_desc_image + + /* Convert an inode number to the dinode on disk. */ + EXT2FS_EI struct ext2_inode * +-dino (ino_t inum) ++dino_ref (ino_t inum) + { + unsigned long inodes_per_group = sblock->s_inodes_per_group; + unsigned long bg_num = (inum - 1) / inodes_per_group; + unsigned long group_inum = (inum - 1) % inodes_per_group; +- struct ext2_group_desc *bg = group_desc(bg_num); ++ struct ext2_group_desc *bg = group_desc (bg_num); + block_t block = bg->bg_inode_table + (group_inum / inodes_per_block); +- return ((struct ext2_inode *)bptr(block)) + group_inum % inodes_per_block; ++ struct ext2_inode *inode = disk_cache_block_ref (block); ++ inode += group_inum % inodes_per_block; ++ ext2_debug ("(%qd) = %p", inum, inode); ++ return inode; ++} ++ ++EXT2FS_EI void ++dino_deref (struct ext2_inode *inode) ++{ ++ ext2_debug ("(%p)", inode); ++ disk_cache_block_deref (inode); + } + + /* ---------------------------------------------------------------- */ +@@ -356,27 +447,38 @@ global_block_modified (block_t block) + EXT2FS_EI void + record_global_poke (void *ptr) + { +- int boffs = trunc_block (bptr_offs (ptr)); +- global_block_modified (boffs_block (boffs)); +- pokel_add (&global_pokel, boffs_ptr(boffs), block_size); ++ block_t block = boffs_block (bptr_offs (ptr)); ++ void *block_ptr = bptr (block); ++ ext2_debug ("(%p = %p)", ptr, block_ptr); ++ assert (disk_cache_block_is_ref (block)); ++ global_block_modified (block); ++ pokel_add (&global_pokel, block_ptr, block_size); + } + + /* This syncs a modification to a non-file block. */ + EXT2FS_EI void + sync_global_ptr (void *bptr, int wait) + { +- vm_offset_t boffs = trunc_block (bptr_offs (bptr)); +- global_block_modified (boffs_block (boffs)); +- pager_sync_some (diskfs_disk_pager, trunc_page (boffs), vm_page_size, wait); ++ block_t block = boffs_block (bptr_offs (bptr)); ++ void *block_ptr = bptr (block); ++ ext2_debug ("(%p -> %u)", bptr, (block_t)block); ++ global_block_modified (block); ++ disk_cache_block_deref (block_ptr); ++ pager_sync_some (diskfs_disk_pager, ++ block_ptr - disk_cache, block_size, wait); ++ + } + + /* This records a modification to one of a file's indirect blocks. */ + EXT2FS_EI void + record_indir_poke (struct node *node, void *ptr) + { +- int boffs = trunc_block (bptr_offs (ptr)); +- global_block_modified (boffs_block (boffs)); +- pokel_add (&node->dn->indir_pokel, boffs_ptr(boffs), block_size); ++ block_t block = boffs_block (bptr_offs (ptr)); ++ void *block_ptr = bptr (block); ++ ext2_debug ("(%d, %p)", (int)node->cache_id, ptr); ++ assert (disk_cache_block_is_ref (block)); ++ global_block_modified (block); ++ pokel_add (&node->dn->indir_pokel, block_ptr, block_size); + } + + /* ---------------------------------------------------------------- */ +@@ -384,6 +486,7 @@ record_indir_poke (struct node *node, vo + EXT2FS_EI void + sync_global (int wait) + { ++ ext2_debug ("%d", wait); + pokel_sync (&global_pokel, wait); + } + +--- a/ext2fs/getblk.c ++++ b/ext2fs/getblk.c +@@ -52,7 +52,7 @@ ext2_discard_prealloc (struct node *node + if (node->dn->info.i_prealloc_count) + { + int i = node->dn->info.i_prealloc_count; +- ext2_debug ("discarding %d prealloced blocks for inode %d", ++ ext2_debug ("discarding %d prealloced blocks for inode %Ld", + i, node->cache_id); + node->dn->info.i_prealloc_count = 0; + ext2_free_blocks (node->dn->info.i_prealloc_block, i); +@@ -104,8 +104,8 @@ ext2_alloc_block (struct node *node, blo + + if (result && zero) + { +- char *bh = bptr (result); +- bzero (bh, block_size); ++ char *bh = disk_cache_block_ref (result); ++ memset (bh, 0, block_size); + record_indir_poke (node, bh); + } + +@@ -122,6 +122,8 @@ inode_getblk (struct node *node, int nr, + block_t hint; + #endif + ++ assert (0 <= nr && nr < EXT2_N_BLOCKS); ++ + *result = node->dn->info.i_data[nr]; + if (*result) + return 0; +@@ -180,14 +182,20 @@ block_getblk (struct node *node, block_t + { + int i; + block_t goal = 0; +- block_t *bh = (block_t *)bptr (block); ++ block_t *bh = (block_t *)disk_cache_block_ref (block); + + *result = bh[nr]; + if (*result) +- return 0; ++ { ++ disk_cache_block_deref (bh); ++ return 0; ++ } + + if (!create) +- return EINVAL; ++ { ++ disk_cache_block_deref (bh); ++ return EINVAL; ++ } + + if (node->dn->info.i_next_alloc_block == new_block) + goal = node->dn->info.i_next_alloc_goal; +@@ -207,7 +215,10 @@ block_getblk (struct node *node, block_t + + *result = ext2_alloc_block (node, goal, zero); + if (!*result) +- return ENOSPC; ++ { ++ disk_cache_block_deref (bh); ++ return ENOSPC; ++ } + + bh[nr] = *result; + +@@ -243,9 +254,9 @@ ext2_getblk (struct node *node, block_t + return EIO; + } + /* +- * If this is a sequential block allocation, set the next_alloc_block +- * to this block now so that all the indblock and data block +- * allocations use the same goal zone ++ * If this is a sequential block allocation, set the next_alloc_block ++ * to this block now so that all the indblock and data block ++ * allocations use the same goal zone + */ + + ext2_debug ("block = %u, next = %u, goal = %u", block, +--- a/ext2fs/hyper.c ++++ b/ext2fs/hyper.c +@@ -58,12 +58,15 @@ static int ext2fs_clean; /* fs clean bef + void + get_hypermetadata (void) + { +- error_t err = diskfs_catch_exception (); +- if (err) +- ext2_panic ("can't read superblock: %s", strerror (err)); +- +- sblock = (struct ext2_super_block *) boffs_ptr (SBLOCK_OFFS); ++ error_t err; ++ size_t read = 0; + ++ assert (! sblock); ++ err = store_read (store, SBLOCK_OFFS >> store->log2_block_size, ++ SBLOCK_SIZE, (void **)&sblock, &read); ++ if (err || read != SBLOCK_SIZE) ++ ext2_panic ("Cannot read hypermetadata"); ++ + if (sblock->s_magic != EXT2_SUPER_MAGIC + #ifdef EXT2FS_PRE_02B_COMPAT + && sblock->s_magic != EXT2_PRE_02B_MAGIC +@@ -152,15 +155,22 @@ get_hypermetadata (void) + + allocate_mod_map (); + +- diskfs_end_catch_exception (); ++ /* A handy source of page-aligned zeros. */ ++ if (zeroblock == 0) ++ zeroblock = (vm_address_t) mmap (0, block_size, PROT_READ, MAP_ANON, 0, 0); ++ ++ munmap (sblock, SBLOCK_SIZE); ++ sblock = NULL; ++} ++ ++void ++map_hypermetadata (void) ++{ ++ sblock = (struct ext2_super_block *) boffs_ptr (SBLOCK_OFFS); + + /* Cache a convenient pointer to the block group descriptors for allocation. + These are stored in the filesystem blocks following the superblock. */ + group_desc_image = (struct ext2_group_desc *) bptr (bptr_block (sblock) + 1); +- +- /* A handy source of page-aligned zeros. */ +- if (zeroblock == 0) +- zeroblock = (vm_address_t) mmap (0, block_size, PROT_READ, MAP_ANON, 0, 0); + } + + error_t +@@ -183,6 +193,7 @@ diskfs_set_hypermetadata (int wait, int + if (sblock_dirty) + { + sblock_dirty = 0; ++ disk_cache_block_ref_ptr (sblock); + record_global_poke (sblock); + } + +@@ -199,7 +210,8 @@ diskfs_readonly_changed (int readonly) + + (*(readonly ? store_set_flags : store_clear_flags)) (store, STORE_READONLY); + +- mprotect (disk_image, store->size, PROT_READ | (readonly ? 0 : PROT_WRITE)); ++ mprotect (disk_cache, disk_cache_size, ++ PROT_READ | (readonly ? 0 : PROT_WRITE)); + + if (!readonly && !(sblock->s_state & EXT2_VALID_FS)) + ext2_warning ("UNCLEANED FILESYSTEM NOW WRITABLE"); +--- a/ext2fs/ialloc.c ++++ b/ext2fs/ialloc.c +@@ -60,7 +60,7 @@ diskfs_free_node (struct node *np, mode_ + + assert (!diskfs_readonly); + +- ext2_debug ("freeing inode %u", inum); ++ ext2_debug ("freeing inode %Lu", inum); + + spin_lock (&global_lock); + +@@ -75,22 +75,25 @@ diskfs_free_node (struct node *np, mode_ + bit = (inum - 1) % sblock->s_inodes_per_group; + + gdp = group_desc (block_group); +- bh = bptr (gdp->bg_inode_bitmap); ++ bh = disk_cache_block_ref (gdp->bg_inode_bitmap); + + if (!clear_bit (bit, bh)) + ext2_warning ("bit already cleared for inode %Ld", inum); + else + { ++ disk_cache_block_ref_ptr (bh); + record_global_poke (bh); + + gdp->bg_free_inodes_count++; + if (S_ISDIR (old_mode)) + gdp->bg_used_dirs_count--; ++ disk_cache_block_ref_ptr (gdp); + record_global_poke (gdp); + + sblock->s_free_inodes_count++; + } + ++ disk_cache_block_deref (bh); + sblock_dirty = 1; + spin_unlock (&global_lock); + alloc_sync(0); +@@ -111,14 +114,15 @@ diskfs_free_node (struct node *np, mode_ + ino_t + ext2_alloc_inode (ino_t dir_inum, mode_t mode) + { +- char *bh; ++ char *bh = 0; + int i, j, inum, avefreei; + struct ext2_group_desc *gdp; + struct ext2_group_desc *tmp; + + spin_lock (&global_lock); + +-repeat: ++ repeat: ++ assert (! bh); + gdp = NULL; + i = 0; + +@@ -213,7 +217,7 @@ repeat: + return 0; + } + +- bh = bptr (gdp->bg_inode_bitmap); ++ bh = disk_cache_block_ref (gdp->bg_inode_bitmap); + if ((inum = + find_first_zero_bit ((unsigned long *) bh, sblock->s_inodes_per_group)) + < sblock->s_inodes_per_group) +@@ -221,12 +225,17 @@ repeat: + if (set_bit (inum, bh)) + { + ext2_warning ("bit already set for inode %d", inum); ++ disk_cache_block_deref (bh); ++ bh = 0; + goto repeat; + } + record_global_poke (bh); ++ bh = 0; + } + else + { ++ disk_cache_block_deref (bh); ++ bh = 0; + if (gdp->bg_free_inodes_count != 0) + { + ext2_error ("free inodes count corrupted in group %d", i); +@@ -248,15 +257,25 @@ repeat: + gdp->bg_free_inodes_count--; + if (S_ISDIR (mode)) + gdp->bg_used_dirs_count++; ++ disk_cache_block_ref_ptr (gdp); + record_global_poke (gdp); + + sblock->s_free_inodes_count--; + sblock_dirty = 1; + + sync_out: ++ assert (! bh); + spin_unlock (&global_lock); + alloc_sync (0); + ++ /* Make sure the coming read_node won't complain about bad ++ fields. */ ++ { ++ struct ext2_inode *di = dino_ref (inum); ++ memset (di, 0, sizeof *di); ++ dino_deref (di); ++ } ++ + return inum; + } + +@@ -354,10 +373,12 @@ ext2_count_free_inodes () + gdp = NULL; + for (i = 0; i < groups_count; i++) + { ++ void *bh; + gdp = group_desc (i); + desc_count += gdp->bg_free_inodes_count; +- x = count_free (bptr (gdp->bg_inode_bitmap), +- sblock->s_inodes_per_group / 8); ++ bh = disk_cache_block_ref (gdp->bg_inode_bitmap); ++ x = count_free (bh, sblock->s_inodes_per_group / 8); ++ disk_cache_block_deref (bh); + ext2_debug ("group %d: stored = %d, counted = %lu", + i, gdp->bg_free_inodes_count, x); + bitmap_count += x; +@@ -387,10 +408,12 @@ ext2_check_inodes_bitmap () + gdp = NULL; + for (i = 0; i < groups_count; i++) + { ++ void *bh; + gdp = group_desc (i); + desc_count += gdp->bg_free_inodes_count; +- x = count_free (bptr (gdp->bg_inode_bitmap), +- sblock->s_inodes_per_group / 8); ++ bh = disk_cache_block_ref (gdp->bg_inode_bitmap); ++ x = count_free (bh, sblock->s_inodes_per_group / 8); ++ disk_cache_block_deref (bh); + if (gdp->bg_free_inodes_count != x) + ext2_error ("wrong free inodes count in group %d, " + "stored = %d, counted = %lu", +--- a/ext2fs/inode.c ++++ b/ext2fs/inode.c +@@ -92,7 +92,7 @@ diskfs_cached_lookup (ino_t inum, struct + dn->dir_idx = 0; + dn->pager = 0; + rwlock_init (&dn->alloc_lock); +- pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_image); ++ pokel_init (&dn->indir_pokel, diskfs_disk_pager, disk_cache); + + /* Create the new node. */ + np = diskfs_make_node (dn); +@@ -201,13 +201,17 @@ read_node (struct node *np) + error_t err; + struct stat *st = &np->dn_stat; + struct disknode *dn = np->dn; +- struct ext2_inode *di = dino (np->cache_id); ++ struct ext2_inode *di; + struct ext2_inode_info *info = &dn->info; + ++ ext2_debug ("(%d)", np->cache_id); ++ + err = diskfs_catch_exception (); + if (err) + return err; + ++ di = dino_ref (np->cache_id); ++ + st->st_fstype = FSTYPE_EXT2FS; + st->st_fsid = getpid (); /* This call is very cheap. */ + st->st_ino = np->cache_id; +@@ -285,7 +289,9 @@ read_node (struct node *np) + info->i_high_size = di->i_size_high; + if (info->i_high_size) /* XXX */ + { ++ dino_deref (di); + ext2_warning ("cannot handle large file inode %Ld", np->cache_id); ++ diskfs_end_catch_exception (); + return EFBIG; + } + } +@@ -307,20 +313,12 @@ read_node (struct node *np) + } + dn->info_i_translator = di->i_translator; + ++ dino_deref (di); + diskfs_end_catch_exception (); + + if (S_ISREG (st->st_mode) || S_ISDIR (st->st_mode) + || (S_ISLNK (st->st_mode) && st->st_blocks)) +- { +- unsigned offset; +- +- np->allocsize = np->dn_stat.st_size; +- +- /* Round up to a block multiple. */ +- offset = np->allocsize & ((1 << log2_block_size) - 1); +- if (offset > 0) +- np->allocsize += block_size - offset; +- } ++ np->allocsize = round_block (np->dn_stat.st_size); + else + /* Allocsize should be zero for anything except directories, files, and + long symlinks. These are the only things allowed to have any blocks +@@ -408,7 +406,9 @@ write_node (struct node *np) + { + error_t err; + struct stat *st = &np->dn_stat; +- struct ext2_inode *di = dino (np->cache_id); ++ struct ext2_inode *di; ++ ++ ext2_debug ("(%d)", np->cache_id); + + if (np->dn->info.i_prealloc_count) + ext2_discard_prealloc (np); +@@ -419,12 +419,14 @@ write_node (struct node *np) + + assert (!diskfs_readonly); + +- ext2_debug ("writing inode %d to disk", np->cache_id); ++ ext2_debug ("writing inode %Ld to disk", np->cache_id); + + err = diskfs_catch_exception (); + if (err) + return NULL; + ++ di = dino_ref (np->cache_id); ++ + di->i_generation = st->st_gen; + + /* We happen to know that the stat mode bits are the same +@@ -505,6 +507,7 @@ write_node (struct node *np) + diskfs_end_catch_exception (); + np->dn_stat_dirty = 0; + ++ /* Leave invoking dino_deref (di) to the caller. */ + return di; + } + else +@@ -664,7 +667,7 @@ diskfs_set_translator (struct node *np, + if (err) + return err; + +- di = dino (np->cache_id); ++ di = dino_ref (np->cache_id); + blkno = di->i_translator; + + if (namelen && !blkno) +@@ -677,6 +680,7 @@ diskfs_set_translator (struct node *np, + 0, 0, 0); + if (blkno == 0) + { ++ dino_deref (di); + diskfs_end_catch_exception (); + return ENOSPC; + } +@@ -700,15 +704,20 @@ diskfs_set_translator (struct node *np, + np->dn_stat.st_mode &= ~S_IPTRANS; + np->dn_set_ctime = 1; + } ++ else ++ dino_deref (di); + + if (namelen) + { ++ void *blkptr; ++ + buf[0] = namelen & 0xFF; + buf[1] = (namelen >> 8) & 0xFF; +- bcopy (name, buf + 2, namelen); ++ memcpy (buf + 2, name, namelen); + +- bcopy (buf, bptr (blkno), block_size); +- record_global_poke (bptr (blkno)); ++ blkptr = disk_cache_block_ref (blkno); ++ memcpy (blkptr, buf, block_size); ++ record_global_poke (blkptr); + + np->dn_stat.st_mode |= S_IPTRANS; + np->dn_set_ctime = 1; +@@ -726,7 +735,7 @@ diskfs_get_translator (struct node *np, + error_t err = 0; + daddr_t blkno; + unsigned datalen; +- const void *transloc; ++ void *transloc; + + assert (sblock->s_creator_os == EXT2_OS_HURD); + +@@ -734,9 +743,11 @@ diskfs_get_translator (struct node *np, + if (err) + return err; + +- blkno = (dino (np->cache_id))->i_translator; ++ struct ext2_inode *di = dino_ref (np->cache_id); ++ blkno = di->i_translator; ++ dino_deref (di); + assert (blkno); +- transloc = bptr (blkno); ++ transloc = disk_cache_block_ref (blkno); + + datalen = + ((unsigned char *)transloc)[0] + (((unsigned char *)transloc)[1] << 8); +@@ -751,6 +762,7 @@ diskfs_get_translator (struct node *np, + memcpy (*namep, transloc + 2, datalen); + } + ++ disk_cache_block_deref (transloc); + diskfs_end_catch_exception (); + + *namelen = datalen; +@@ -772,7 +784,7 @@ write_symlink (struct node *node, const + + assert (node->dn_stat.st_blocks == 0); + +- bcopy (target, node->dn->info.i_data, len); ++ memcpy (node->dn->info.i_data, target, len); + node->dn_stat.st_size = len - 1; + node->dn_set_ctime = 1; + node->dn_set_mtime = 1; +@@ -789,7 +801,7 @@ read_symlink (struct node *node, char *t + + assert (node->dn_stat.st_size < MAX_INODE_SYMLINK); + +- bcopy (node->dn->info.i_data, target, node->dn_stat.st_size); ++ memcpy (target, node->dn->info.i_data, node->dn_stat.st_size); + return 0; + } + +--- a/ext2fs/pager.c ++++ b/ext2fs/pager.c +@@ -18,17 +18,18 @@ + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + ++#include <unistd.h> + #include <string.h> + #include <errno.h> + #include <hurd/store.h> + #include "ext2fs.h" + ++/* XXX */ ++#include "../libpager/priv.h" ++ + /* A ports bucket to hold pager ports. */ + struct port_bucket *pager_bucket; + +-/* Mapped image of the disk. */ +-void *disk_image; +- + spin_lock_t node_to_page_lock = SPIN_LOCK_INITIALIZER; + + #ifdef DONT_CACHE_MEMORY_OBJECTS +@@ -163,6 +164,9 @@ file_pager_read_page (struct node *node, + block_t pending_blocks = 0; + int num_pending_blocks = 0; + ++ ext2_debug ("reading inode %Ld page %u[%d]", ++ node->cache_id, page, vm_page_size); ++ + /* Read the NUM_PENDING_BLOCKS blocks in PENDING_BLOCKS, into the buffer + pointed to by BUF (allocating it if necessary) at offset OFFS. OFFS in + adjusted by the amount read, and NUM_PENDING_BLOCKS is zeroed. Any read +@@ -171,7 +175,8 @@ file_pager_read_page (struct node *node, + { + if (num_pending_blocks > 0) + { +- block_t dev_block = pending_blocks << log2_dev_blocks_per_fs_block; ++ store_offset_t dev_block = (store_offset_t) pending_blocks ++ << log2_dev_blocks_per_fs_block; + size_t amount = num_pending_blocks << log2_block_size; + /* The buffer we try to read into; on the first read, we pass in a + size of zero, so that the read is guaranteed to allocate a new +@@ -198,7 +203,7 @@ file_pager_read_page (struct node *node, + else + /* We've already got some buffer, so copy into it. */ + { +- bcopy (new_buf, *buf + offs, new_len); ++ memcpy (*buf + offs, new_buf, new_len); + free_page_buf (new_buf); /* Return NEW_BUF to our pool. */ + STAT_INC (file_pagein_freed_bufs); + } +@@ -254,7 +259,7 @@ file_pager_read_page (struct node *node, + break; + STAT_INC (file_pagein_alloced_bufs); + } +- bzero (*buf + offs, block_size); ++ memset (*buf + offs, 0, block_size); + offs += block_size; + } + else +@@ -295,16 +300,17 @@ pending_blocks_write (struct pending_blo + if (pb->num > 0) + { + error_t err; +- block_t dev_block = pb->block << log2_dev_blocks_per_fs_block; ++ store_offset_t dev_block = (store_offset_t) pb->block ++ << log2_dev_blocks_per_fs_block; + size_t length = pb->num << log2_block_size, amount; + +- ext2_debug ("writing block %u[%ld]", pb->block, pb->num); ++ ext2_debug ("writing block %u[%Ld]", pb->block, pb->num); + + if (pb->offs > 0) + /* Put what we're going to write into a page-aligned buffer. */ + { + void *page_buf = get_page_buf (); +- bcopy (pb->buf + pb->offs, (void *)page_buf, length); ++ memcpy ((void *)page_buf, pb->buf + pb->offs, length); + err = store_write (store, dev_block, page_buf, length, &amount); + free_page_buf (page_buf); + } +@@ -357,7 +363,7 @@ pending_blocks_add (struct pending_block + return 0; + } + +-/* Write one page for the pager backing NODE, at offset PAGE, into BUF. This ++/* Write one page for the pager backing NODE, at OFFSET, into BUF. This + may need to write several filesystem blocks to satisfy one page, and tries + to consolidate the i/o if possible. */ + static error_t +@@ -381,7 +387,7 @@ file_pager_write_page (struct node *node + else if (offset + left > node->allocsize) + left = node->allocsize - offset; + +- ext2_debug ("writing inode %d page %d[%d]", node->cache_id, offset, left); ++ ext2_debug ("writing inode %Ld page %u[%d]", node->cache_id, offset, left); + + STAT_INC (file_pageouts); + +@@ -409,16 +415,31 @@ disk_pager_read_page (vm_offset_t page, + { + error_t err; + size_t length = vm_page_size, read = 0; +- vm_size_t dev_end = store->size; ++ store_offset_t offset = page, dev_end = store->size; + +- if (page + vm_page_size > dev_end) +- length = dev_end - page; ++ mutex_lock (&disk_cache_lock); ++ int index = offset >> log2_block_size; ++ offset = ((store_offset_t) disk_cache_info[index].block << log2_block_size) ++ + offset % block_size; ++ disk_cache_info[index].flags |= DC_INCORE; ++ disk_cache_info[index].flags &=~ DC_UNTOUCHED; ++#ifndef NDEBUG ++ disk_cache_info[index].last_read = disk_cache_info[index].block; ++ disk_cache_info[index].last_read_xor ++ = disk_cache_info[index].block ^ DISK_CACHE_LAST_READ_XOR; ++#endif ++ ext2_debug ("(%Ld)", offset >> log2_block_size); ++ mutex_unlock (&disk_cache_lock); ++ ++ if (offset + vm_page_size > dev_end) ++ length = dev_end - offset; + +- err = store_read (store, page >> store->log2_block_size, length, buf, &read); ++ err = store_read (store, offset >> store->log2_block_size, length, ++ buf, &read); + if (read != length) + return EIO; + if (!err && length != vm_page_size) +- bzero ((void *)(*buf + length), vm_page_size - length); ++ memset ((void *)(*buf + length), 0, vm_page_size - length); + + *writelock = 0; + +@@ -430,26 +451,38 @@ disk_pager_write_page (vm_offset_t page, + { + error_t err = 0; + size_t length = vm_page_size, amount; +- vm_size_t dev_end = store->size; ++ store_offset_t offset = page, dev_end = store->size; ++ ++ mutex_lock (&disk_cache_lock); ++ int index = offset >> log2_block_size; ++ assert (disk_cache_info[index].block != DC_NO_BLOCK); ++ offset = ((store_offset_t) disk_cache_info[index].block << log2_block_size) ++ + offset % block_size; ++#ifndef NDEBUG /* Not strictly needed. */ ++ assert ((disk_cache_info[index].last_read ^ DISK_CACHE_LAST_READ_XOR) ++ == disk_cache_info[index].last_read_xor); ++ assert (disk_cache_info[index].last_read ++ == disk_cache_info[index].block); ++#endif ++ mutex_unlock (&disk_cache_lock); + +- if (page + vm_page_size > dev_end) +- length = dev_end - page; ++ if (offset + vm_page_size > dev_end) ++ length = dev_end - offset; + +- ext2_debug ("writing disk page %d[%d]", page, length); ++ ext2_debug ("writing disk page %Ld[%d]", offset, length); + + STAT_INC (disk_pageouts); + + if (modified_global_blocks) + /* Be picky about which blocks in a page that we write. */ + { +- vm_offset_t offs = page; + struct pending_blocks pb; + + pending_blocks_init (&pb, buf); + + while (length > 0 && !err) + { +- block_t block = boffs_block (offs); ++ block_t block = boffs_block (offset); + + /* We don't clear the block modified bit here because this paging + write request may not be the same one that actually set the bit, +@@ -467,7 +500,7 @@ disk_pager_write_page (vm_offset_t page, + /* Otherwise just skip it. */ + err = pending_blocks_skip (&pb); + +- offs += block_size; ++ offset += block_size; + length -= block_size; + } + +@@ -476,7 +509,7 @@ disk_pager_write_page (vm_offset_t page, + } + else + { +- err = store_write (store, page >> store->log2_block_size, ++ err = store_write (store, offset >> store->log2_block_size, + buf, length, &amount); + if (!err && length != amount) + err = EIO; +@@ -484,6 +517,18 @@ disk_pager_write_page (vm_offset_t page, + + return err; + } ++ ++static void ++disk_pager_notify_evict (vm_offset_t page) ++{ ++ int index = page >> log2_block_size; ++ ++ ext2_debug ("(block %u)", index); ++ ++ mutex_lock (&disk_cache_lock); ++ disk_cache_info[index].flags &= ~DC_INCORE; ++ mutex_unlock (&disk_cache_lock); ++} + + /* Satisfy a pager read request for either the disk pager or file pager + PAGER, to the page at offset PAGE into BUF. WRITELOCK should be set if +@@ -493,9 +538,11 @@ pager_read_page (struct user_pager_info + vm_address_t *buf, int *writelock) + { + if (pager->type == DISK) +- return disk_pager_read_page (page, (void **)buf, writelock); ++ return disk_pager_read_page (page, (void **)buf, ++ writelock); + else +- return file_pager_read_page (pager->node, page, (void **)buf, writelock); ++ return file_pager_read_page (pager->node, page, (void **)buf, ++ writelock); + } + + /* Satisfy a pager write request for either the disk pager or file pager +@@ -509,6 +556,14 @@ pager_write_page (struct user_pager_info + else + return file_pager_write_page (pager->node, page, (void *)buf); + } ++ ++void ++pager_notify_evict (struct user_pager_info *pager, vm_offset_t page) ++{ ++ if (pager->type == DISK) ++ disk_pager_notify_evict (page); ++} ++ + + /* Make page PAGE writable, at least up to ALLOCSIZE. This function and + diskfs_grow are the only places that blocks are actually added to the +@@ -558,10 +613,10 @@ pager_unlock_page (struct user_pager_inf + + #ifdef EXT2FS_DEBUG + if (dn->last_page_partially_writable) +- ext2_debug ("made page %u[%lu] in inode %d partially writable", ++ ext2_debug ("made page %u[%Lu] in inode %Ld partially writable", + page, node->allocsize - page, node->cache_id); + else +- ext2_debug ("made page %u[%u] in inode %d writable", ++ ext2_debug ("made page %u[%u] in inode %Ld writable", + page, vm_page_size, node->cache_id); + #endif + +@@ -619,8 +674,8 @@ diskfs_grow (struct node *node, off_t si + block_t old_page_end_block = + round_page (old_size) >> log2_block_size; + +- ext2_debug ("growing inode %d to %lu bytes (from %lu)", node->cache_id, +- new_size, old_size); ++ ext2_debug ("growing inode %Ld to %Lu bytes (from %Lu)", ++ node->cache_id, new_size, old_size); + + if (dn->last_page_partially_writable + && old_page_end_block > end_block) +@@ -656,11 +711,11 @@ diskfs_grow (struct node *node, off_t si + + STAT_INC (file_grows); + +- ext2_debug ("new size: %ld%s.", new_size, ++ ext2_debug ("new size: %Lu%s.", new_size, + dn->last_page_partially_writable + ? " (last page writable)": ""); + if (err) +- ext2_warning ("inode=%Ld, target=%Ld: %s", ++ ext2_warning ("inode=%Ld, target=%Lu: %s", + node->cache_id, new_size, strerror (err)); + + node->allocsize = new_size; +@@ -765,6 +820,374 @@ pager_dropweak (struct user_pager_info * + { + } + ++/* Cached blocks from disk. */ ++void *disk_cache; ++ ++/* DISK_CACHE size in bytes and blocks. */ ++store_offset_t disk_cache_size; ++int disk_cache_blocks; ++ ++/* block num --> pointer to in-memory block */ ++hurd_ihash_t disk_cache_bptr; ++/* Cached blocks' info. */ ++struct disk_cache_info *disk_cache_info; ++/* Hint index for which cache block to reuse next. */ ++int disk_cache_hint; ++/* Lock for these structures. */ ++struct mutex disk_cache_lock; ++/* Fired when a re-association is done. */ ++struct condition disk_cache_reassociation; ++ ++/* Finish mapping initialization. */ ++static void ++disk_cache_init (void) ++{ ++ if (block_size != vm_page_size) ++ ext2_panic ("Block size %d != vm_page_size %d", ++ block_size, vm_page_size); ++ ++ mutex_init (&disk_cache_lock); ++ condition_init (&disk_cache_reassociation); ++ ++ /* Allocate space for block num -> in-memory pointer mapping. */ ++ if (hurd_ihash_create (&disk_cache_bptr, HURD_IHASH_NO_LOCP)) ++ ext2_panic ("Can't allocate memory for disk_pager_bptr"); ++ ++ /* Allocate space for disk cache blocks' info. */ ++ disk_cache_info = malloc ((sizeof *disk_cache_info) * disk_cache_blocks); ++ if (!disk_cache_info) ++ ext2_panic ("Cannot allocate space for disk cache info"); ++ ++ /* Initialize disk_cache_info. */ ++ for (int i = 0; i < disk_cache_blocks; i++) ++ { ++ disk_cache_info[i].block = DC_NO_BLOCK; ++ disk_cache_info[i].flags = 0; ++ disk_cache_info[i].ref_count = 0; ++#ifndef NDEBUG ++ disk_cache_info[i].last_read = DC_NO_BLOCK; ++ disk_cache_info[i].last_read_xor ++ = DC_NO_BLOCK ^ DISK_CACHE_LAST_READ_XOR; ++#endif ++ } ++ disk_cache_hint = 0; ++ ++ /* Map the superblock and the block group descriptors. */ ++ block_t fixed_first = boffs_block (SBLOCK_OFFS); ++ block_t fixed_last = fixed_first ++ + (round_block ((sizeof *group_desc_image) * groups_count) ++ >> log2_block_size); ++ ext2_debug ("%d-%d\n", fixed_first, fixed_last); ++ assert (fixed_last - fixed_first + 1 <= (block_t)disk_cache_blocks + 3); ++ for (block_t i = fixed_first; i <= fixed_last; i++) ++ { ++ disk_cache_block_ref (i); ++ assert (disk_cache_info[i-fixed_first].block == i); ++ disk_cache_info[i-fixed_first].flags |= DC_FIXED; ++ } ++} ++ ++static void ++disk_cache_return_unused (void) ++{ ++ int index; ++ ++ /* XXX: Touch all pages. It seems that sometimes GNU Mach "forgets" ++ to notify us about evicted pages. Disk cache must be ++ unlocked. */ ++ for (vm_offset_t i = 0; i < disk_cache_size; i += vm_page_size) ++ *(volatile char *)(disk_cache + i); ++ ++ /* Release some references to cached blocks. */ ++ pokel_sync (&global_pokel, 1); ++ ++ /* Return unused pages that are in core. */ ++ int pending_begin = -1, pending_end = -1; ++ mutex_lock (&disk_cache_lock); ++ for (index = 0; index < disk_cache_blocks; index++) ++ if (! (disk_cache_info[index].flags & (DC_DONT_REUSE & ~DC_INCORE)) ++ && ! disk_cache_info[index].ref_count) ++ { ++ ext2_debug ("return %u -> %d", ++ disk_cache_info[index].block, index); ++ if (index != pending_end) ++ { ++ /* Return previous region, if there is such, ... */ ++ if (pending_end >= 0) ++ { ++ mutex_unlock (&disk_cache_lock); ++ pager_return_some (diskfs_disk_pager, ++ pending_begin * vm_page_size, ++ (pending_end - pending_begin) ++ * vm_page_size, ++ 1); ++ mutex_lock (&disk_cache_lock); ++ } ++ /* ... and start new region. */ ++ pending_begin = index; ++ } ++ pending_end = index + 1; ++ } ++ ++ mutex_unlock (&disk_cache_lock); ++ ++ /* Return last region, if there is such. */ ++ if (pending_end >= 0) ++ pager_return_some (diskfs_disk_pager, ++ pending_begin * vm_page_size, ++ (pending_end - pending_begin) * vm_page_size, ++ 1); ++ else ++ { ++ printf ("ext2fs: disk cache is starving\n"); ++ ++ /* Give it some time. This should happen rarely. */ ++ sleep (1); ++ } ++} ++ ++/* Map block and return pointer to it. */ ++void * ++disk_cache_block_ref (block_t block) ++{ ++ int index; ++ void *bptr; ++ ++ assert (0 <= block && block < store->size >> log2_block_size); ++ ++ ext2_debug ("(%u)", block); ++ ++ mutex_lock (&disk_cache_lock); ++ ++ bptr = hurd_ihash_find (disk_cache_bptr, block); ++ if (bptr) ++ /* Already mapped. */ ++ { ++ index = bptr_index (bptr); ++ ++ /* In process of re-associating? */ ++ if (disk_cache_info[index].flags & DC_UNTOUCHED) ++ { ++ /* Wait re-association to finish. */ ++ condition_wait (&disk_cache_reassociation, &disk_cache_lock); ++ mutex_unlock (&disk_cache_lock); ++ ++#if 0 ++ printf ("Re-association -- wait finished.\n"); ++#endif ++ ++ /* Try again. */ ++ return disk_cache_block_ref (block); /* tail recursion */ ++ } ++ ++ /* Just increment reference and return. */ ++ assert (disk_cache_info[index].ref_count + 1 ++ > disk_cache_info[index].ref_count); ++ disk_cache_info[index].ref_count++; ++ ++ ext2_debug ("cached %u -> %d (ref_count = %d, flags = 0x%x, ptr = %p)", ++ disk_cache_info[index].block, index, ++ disk_cache_info[index].ref_count, ++ disk_cache_info[index].flags, bptr); ++ ++ mutex_unlock (&disk_cache_lock); ++ ++ return bptr; ++ } ++ ++ /* Search for a block that is not in core and is not referenced. */ ++ index = disk_cache_hint; ++ while ((disk_cache_info[index].flags & DC_DONT_REUSE) ++ || (disk_cache_info[index].ref_count)) ++ { ++ ext2_debug ("reject %u -> %d (ref_count = %d, flags = 0x%x)", ++ disk_cache_info[index].block, index, ++ disk_cache_info[index].ref_count, ++ disk_cache_info[index].flags); ++ ++ /* Just move to next block. */ ++ index++; ++ if (index >= disk_cache_blocks) ++ index -= disk_cache_blocks; ++ ++ /* If we return to where we started, than there is no suitable ++ block. */ ++ if (index == disk_cache_hint) ++ break; ++ } ++ ++ /* The next place in the disk cache becomes the current hint. */ ++ disk_cache_hint = index + 1; ++ if (disk_cache_hint >= disk_cache_blocks) ++ disk_cache_hint -= disk_cache_blocks; ++ ++ /* Is suitable place found? */ ++ if ((disk_cache_info[index].flags & DC_DONT_REUSE) ++ || disk_cache_info[index].ref_count) ++ /* No place is found. Try to release some blocks and try ++ again. */ ++ { ++ ext2_debug ("flush %u -> %d", disk_cache_info[index].block, index); ++ ++ mutex_unlock (&disk_cache_lock); ++ ++ disk_cache_return_unused (); ++ ++ return disk_cache_block_ref (block); /* tail recursion */ ++ } ++ ++ /* Suitable place is found. */ ++ ++ /* Calculate pointer to data. */ ++ bptr = (char *)disk_cache + (index << log2_block_size); ++ ext2_debug ("map %u -> %d (%p)", block, index, bptr); ++ ++ /* This pager_return_some is used only to set PM_FORCEREAD for the ++ page. DC_UNTOUCHED is set so that we catch if someone has ++ referenced the block while we didn't hold disk_cache_lock. */ ++ disk_cache_info[index].flags |= DC_UNTOUCHED; ++ ++#if 0 /* XXX: Let's see if this is needed at all. */ ++ ++ mutex_unlock (&disk_cache_lock); ++ pager_return_some (diskfs_disk_pager, bptr - disk_cache, vm_page_size, 1); ++ mutex_lock (&disk_cache_lock); ++ ++ /* Has someone used our bptr? Has someone mapped requested block ++ while we have unlocked disk_cache_lock? If so, environment has ++ changed and we have to restart operation. */ ++ if ((! (disk_cache_info[index].flags & DC_UNTOUCHED)) ++ || hurd_ihash_find (disk_cache_bptr, block)) ++ { ++ mutex_unlock (&disk_cache_lock); ++ return disk_cache_block_ref (block); /* tail recursion */ ++ } ++ ++#elif 0 ++ ++ /* XXX: Use libpager internals. */ ++ ++ mutex_lock (&diskfs_disk_pager->interlock); ++ int page = (bptr - disk_cache) / vm_page_size; ++ assert (page >= 0); ++ int is_incore = (page < diskfs_disk_pager->pagemapsize ++ && (diskfs_disk_pager->pagemap[page] & PM_INCORE)); ++ mutex_unlock (&diskfs_disk_pager->interlock); ++ if (is_incore) ++ { ++ mutex_unlock (&disk_cache_lock); ++ printf ("INCORE\n"); ++ return disk_cache_block_ref (block); /* tail recursion */ ++ } ++ ++#endif ++ ++ /* Re-associate. */ ++ if (disk_cache_info[index].block != DC_NO_BLOCK) ++ /* Remove old association. */ ++ hurd_ihash_remove (disk_cache_bptr, disk_cache_info[index].block); ++ /* New association. */ ++ if (hurd_ihash_add (disk_cache_bptr, block, bptr)) ++ ext2_panic ("Couldn't hurd_ihash_add new disk block"); ++ assert (! (disk_cache_info[index].flags & DC_DONT_REUSE & ~DC_UNTOUCHED)); ++ disk_cache_info[index].block = block; ++ assert (! disk_cache_info[index].ref_count); ++ disk_cache_info[index].ref_count = 1; ++ ++ /* All data structures are set up. */ ++ mutex_unlock (&disk_cache_lock); ++ ++ /* Try to read page. */ ++ *(volatile char *) bptr; ++ ++ /* Check if it's actually read. */ ++ mutex_lock (&disk_cache_lock); ++ if (disk_cache_info[index].flags & DC_UNTOUCHED) ++ /* It's not read. */ ++ { ++ /* Remove newly created association. */ ++ hurd_ihash_remove (disk_cache_bptr, block); ++ disk_cache_info[index].block = DC_NO_BLOCK; ++ disk_cache_info[index].flags &=~ DC_UNTOUCHED; ++ disk_cache_info[index].ref_count = 0; ++ mutex_unlock (&disk_cache_lock); ++ ++ /* Prepare next time association of this page to succeed. */ ++ pager_flush_some (diskfs_disk_pager, bptr - disk_cache, ++ vm_page_size, 0); ++ ++#if 0 ++ printf ("Re-association failed.\n"); ++#endif ++ ++ /* Try again. */ ++ return disk_cache_block_ref (block); /* tail recursion */ ++ } ++ mutex_unlock (&disk_cache_lock); ++ ++ /* Re-association was successful. */ ++ condition_broadcast (&disk_cache_reassociation); ++ ++ ext2_debug ("(%u) = %p", block, bptr); ++ return bptr; ++} ++ ++void ++disk_cache_block_ref_ptr (void *ptr) ++{ ++ int index; ++ ++ mutex_lock (&disk_cache_lock); ++ index = bptr_index (ptr); ++ assert (disk_cache_info[index].ref_count >= 1); ++ assert (disk_cache_info[index].ref_count + 1 ++ > disk_cache_info[index].ref_count); ++ disk_cache_info[index].ref_count++; ++ assert (! (disk_cache_info[index].flags & DC_UNTOUCHED)); ++ ext2_debug ("(%p) (ref_count = %d, flags = 0x%x)", ++ ptr, ++ disk_cache_info[index].ref_count, ++ disk_cache_info[index].flags); ++ mutex_unlock (&disk_cache_lock); ++} ++ ++void ++disk_cache_block_deref (void *ptr) ++{ ++ int index; ++ ++ assert (disk_cache <= ptr && ptr <= disk_cache + disk_cache_size); ++ ++ mutex_lock (&disk_cache_lock); ++ index = bptr_index (ptr); ++ ext2_debug ("(%p) (ref_count = %d, flags = 0x%x)", ++ ptr, ++ disk_cache_info[index].ref_count - 1, ++ disk_cache_info[index].flags); ++ assert (! (disk_cache_info[index].flags & DC_UNTOUCHED)); ++ assert (disk_cache_info[index].ref_count >= 1); ++ disk_cache_info[index].ref_count--; ++ mutex_unlock (&disk_cache_lock); ++} ++ ++/* Not used. */ ++int ++disk_cache_block_is_ref (block_t block) ++{ ++ int ref; ++ void *ptr; ++ ++ mutex_lock (&disk_cache_lock); ++ ptr = hurd_ihash_find (disk_cache_bptr, block); ++ if (! ptr) ++ ref = 0; ++ else /* XXX: Should check for DC_UNTOUCHED too. */ ++ ref = disk_cache_info[bptr_index (ptr)].ref_count; ++ mutex_unlock (&disk_cache_lock); ++ ++ return ref; ++} ++ + /* Create the DISK pager. */ + void + create_disk_pager (void) +@@ -774,8 +1197,12 @@ create_disk_pager (void) + ext2_panic ("can't create disk pager: %s", strerror (errno)); + upi->type = DISK; + pager_bucket = ports_create_bucket (); +- diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, store->size, +- &disk_image); ++ get_hypermetadata (); ++ disk_cache_blocks = DISK_CACHE_BLOCKS; ++ disk_cache_size = disk_cache_blocks << log2_block_size; ++ diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, 1, ++ disk_cache_size, &disk_cache); ++ disk_cache_init (); + } + + /* Call this to create a FILE_DATA pager and return a send right. +@@ -815,7 +1242,7 @@ diskfs_get_filemap (struct node *node, v + diskfs_nref_light (node); + node->dn->pager = + pager_create (upi, pager_bucket, MAY_CACHE, +- MEMORY_OBJECT_COPY_DELAY); ++ MEMORY_OBJECT_COPY_DELAY, 0); + if (node->dn->pager == 0) + { + diskfs_nrele_light (node); +--- a/ext2fs/pokel.c ++++ b/ext2fs/pokel.c +@@ -67,12 +67,27 @@ pokel_add (struct pokel *pokel, void *lo + vm_offset_t p_offs = pl->offset; + vm_size_t p_end = p_offs + pl->length; + +- if (p_offs == offset && p_end == end) +- break; ++ if (p_offs <= offset && end <= p_end) ++ { ++ if (pokel->image == disk_cache) ++ for (vm_offset_t i = offset; i < end; i += block_size) ++ disk_cache_block_deref (disk_cache + i); ++ ++ break; ++ } + else if (p_end >= offset && end >= p_offs) + { + pl->offset = offset < p_offs ? offset : p_offs; + pl->length = (end > p_end ? end : p_end) - pl->offset; ++ ++ if (pokel->image == disk_cache) ++ { ++ vm_offset_t i_begin = p_offs > offset ? p_offs : offset; ++ vm_offset_t i_end = p_end < end ? p_end : end; ++ for (vm_offset_t i = i_begin; i < i_end; i += block_size) ++ disk_cache_block_deref (disk_cache + i); ++ } ++ + ext2_debug ("extended 0x%x[%ul] to 0x%x[%ul]", + p_offs, p_end - p_offs, pl->offset, pl->length); + break; +@@ -106,18 +121,28 @@ void + _pokel_exec (struct pokel *pokel, int sync, int wait) + { + struct poke *pl, *pokes, *last = NULL; +- ++ + spin_lock (&pokel->lock); + pokes = pokel->pokes; + pokel->pokes = NULL; + spin_unlock (&pokel->lock); + + for (pl = pokes; pl; last = pl, pl = pl->next) +- if (sync) +- { +- ext2_debug ("syncing 0x%x[%ul]", pl->offset, pl->length); +- pager_sync_some (pokel->pager, pl->offset, pl->length, wait); +- } ++ { ++ if (sync) ++ { ++ ext2_debug ("syncing 0x%x[%ul]", pl->offset, pl->length); ++ pager_sync_some (pokel->pager, pl->offset, pl->length, wait); ++ } ++ ++ if (pokel->image == disk_cache) ++ { ++ vm_offset_t begin = trunc_block (pl->offset); ++ vm_offset_t end = round_block (pl->offset + pl->length); ++ for (vm_offset_t i = begin; i != end; i += block_size) ++ disk_cache_block_deref (pokel->image + i); ++ } ++ } + + if (last) + { +--- a/ext2fs/truncate.c ++++ b/ext2fs/truncate.c +@@ -124,7 +124,7 @@ trunc_indirect (struct node *node, block + { + unsigned index; + int modified = 0, all_freed = 1; +- block_t *ind_bh = (block_t *)bptr (*p); ++ block_t *ind_bh = (block_t *)disk_cache_block_ref (*p); + unsigned first = end < offset ? 0 : end - offset; + + for (index = first; index < addr_per_block; index++) +@@ -139,11 +139,16 @@ trunc_indirect (struct node *node, block + + if (first == 0 && all_freed) + { +- pager_flush_some (diskfs_disk_pager, boffs (*p), block_size, 1); ++ pager_flush_some (diskfs_disk_pager, ++ bptr_index (ind_bh) << log2_block_size, ++ block_size, 1); + free_block_run_free_ptr (fbr, p); ++ disk_cache_block_deref (ind_bh); + } + else if (modified) + record_indir_poke (node, ind_bh); ++ else ++ disk_cache_block_deref (ind_bh); + } + } + +@@ -218,7 +223,7 @@ poke_pages (memory_object_t obj, vm_offs + /* Flush all the data past the new size from the kernel. Also force any + delayed copies of this data to take place immediately. (We are implicitly + changing the data to zeros and doing it without the kernel's immediate +- knowledge; accordingl we must help out the kernel thusly.) */ ++ knowledge; accordingly we must help out the kernel thusly.) */ + static void + force_delayed_copies (struct node *node, off_t length) + { +--- a/fatfs/pager.c ++++ b/fatfs/pager.c +@@ -596,6 +596,13 @@ pager_unlock_page (struct user_pager_inf + return 0; + } + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ assert (!"unrequested notification on eviction"); ++} ++ + /* Grow the disk allocated to locked node NODE to be at least SIZE + bytes, and set NODE->allocsize to the actual allocated size. (If + the allocated size is already SIZE bytes, do nothing.) CRED +@@ -752,7 +759,7 @@ create_fat_pager (void) + struct user_pager_info *upi = malloc (sizeof (struct user_pager_info)); + upi->type = FAT; + pager_bucket = ports_create_bucket (); +- diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, ++ diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, 0, + bytes_per_sector * sectors_per_fat, + &fat_image); + } +@@ -794,7 +801,7 @@ diskfs_get_filemap (struct node *node, v + diskfs_nref_light (node); + node->dn->pager = + pager_create (upi, pager_bucket, MAY_CACHE, +- MEMORY_OBJECT_COPY_DELAY); ++ MEMORY_OBJECT_COPY_DELAY, 0); + if (node->dn->pager == 0) + { + diskfs_nrele_light (node); +--- a/isofs/pager.c ++++ b/isofs/pager.c +@@ -94,6 +94,13 @@ pager_unlock_page (struct user_pager_inf + return EROFS; + } + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ assert (!"unrequested notification on eviction"); ++} ++ + /* Tell how big the file is. */ + error_t + pager_report_extent (struct user_pager_info *pager, +@@ -137,7 +144,7 @@ create_disk_pager (void) + upi->type = DISK; + upi->np = 0; + pager_bucket = ports_create_bucket (); +- diskfs_start_disk_pager (upi, pager_bucket, 1, store->size, &disk_image); ++ diskfs_start_disk_pager (upi, pager_bucket, 1, 0, store->size, &disk_image); + upi->p = diskfs_disk_pager; + } + +@@ -168,7 +175,8 @@ diskfs_get_filemap (struct node *np, vm_ + upi->type = FILE_DATA; + upi->np = np; + diskfs_nref_light (np); +- upi->p = pager_create (upi, pager_bucket, 1, MEMORY_OBJECT_COPY_DELAY); ++ upi->p = pager_create (upi, pager_bucket, 1, ++ MEMORY_OBJECT_COPY_DELAY, 0); + if (upi->p == 0) + { + diskfs_nrele_light (np); +--- a/libdiskfs/disk-pager.c ++++ b/libdiskfs/disk-pager.c +@@ -46,7 +46,8 @@ service_paging_requests (any_t arg) + + void + diskfs_start_disk_pager (struct user_pager_info *upi, +- struct port_bucket *pager_bucket, int may_cache, ++ struct port_bucket *pager_bucket, ++ int may_cache, int notify_on_evict, + size_t size, void **image) + { + error_t err; +@@ -58,7 +59,8 @@ diskfs_start_disk_pager (struct user_pag + + /* Create the pager. */ + diskfs_disk_pager = pager_create (upi, pager_bucket, +- may_cache, MEMORY_OBJECT_COPY_NONE); ++ may_cache, MEMORY_OBJECT_COPY_NONE, ++ notify_on_evict); + assert (diskfs_disk_pager); + + /* Get a port to the disk pager. */ +--- a/libdiskfs/diskfs-pager.h ++++ b/libdiskfs/diskfs-pager.h +@@ -33,7 +33,8 @@ + mapped is returned in IMAGE. INFO, PAGER_BUCKET, & MAY_CACHE are passed + to `pager_create'. */ + extern void diskfs_start_disk_pager (struct user_pager_info *info, +- struct port_bucket *pager_bucket, int may_cache, ++ struct port_bucket *pager_bucket, ++ int may_cache, int notify_on_evict, + size_t size, void **image); + + extern struct pager *diskfs_disk_pager; +--- a/libpager/data-request.c ++++ b/libpager/data-request.c +@@ -40,11 +40,11 @@ _pager_seqnos_memory_object_data_request + if (!p) + return EOPNOTSUPP; + +- /* Acquire the right to meddle with the pagemap */ ++ /* Acquire the right to meddle with the pagemap. */ + mutex_lock (&p->interlock); + _pager_wait_for_seqno (p, seqno); + +- /* sanity checks -- we don't do multi-page requests yet. */ ++ /* Sanity checks -- we don't do multi-page requests yet. */ + if (control != p->memobjcntl) + { + printf ("incg data request: wrong control port\n"); +@@ -121,7 +123,8 @@ _pager_seqnos_memory_object_data_request + goto error_read; + + memory_object_data_supply (p->memobjcntl, offset, page, length, 1, +- write_lock ? VM_PROT_WRITE : VM_PROT_NONE, 0, ++ write_lock ? VM_PROT_WRITE : VM_PROT_NONE, ++ p->notify_on_evict ? 1 : 0, + MACH_PORT_NULL); + mutex_lock (&p->interlock); + _pager_mark_object_error (p, offset, length, 0); +--- a/libpager/data-return.c ++++ b/libpager/data-return.c +@@ -39,6 +39,7 @@ _pager_do_write_request (mach_port_t obj + struct pager *p; + short *pm_entries; + int npages, i; ++ char *notified; + error_t *pagerrs; + struct lock_request *lr; + struct lock_list {struct lock_request *lr; +@@ -71,9 +72,6 @@ _pager_do_write_request (mach_port_t obj + goto release_out; + } + +- if (! dirty) +- goto release_out; +- + if (p->pager_state != NORMAL) + { + printf ("pager in wrong state for write\n"); +@@ -83,6 +81,11 @@ _pager_do_write_request (mach_port_t obj + npages = length / __vm_page_size; + pagerrs = alloca (npages * sizeof (error_t)); + ++ notified = alloca (npages * (sizeof *notified)); ++#ifndef NDEBUG ++ memset (notified, -1, npages * (sizeof *notified)); ++#endif ++ + _pager_block_termination (p); /* until we are done with the pagemap + when the write completes. */ + +@@ -90,6 +93,23 @@ _pager_do_write_request (mach_port_t obj + + pm_entries = &p->pagemap[offset / __vm_page_size]; + ++ if (! dirty && ! kcopy) ++ { ++ /* Prepare notified array. */ ++ for (i = 0; i < npages; i++) ++ notified[i] = (p->notify_on_evict ++ && ! (pm_entries[i] & PM_PAGEINWAIT)); ++ ++ _pager_release_seqno (p, seqno); ++ goto notify; ++ } ++ ++ if (! dirty) ++ { ++ _pager_allow_termination (p); ++ goto release_out; ++ } ++ + /* Make sure there are no other in-progress writes for any of these + pages before we begin. This imposes a little more serialization + than we really have to require (because *all* future writes on +@@ -120,10 +140,6 @@ _pager_do_write_request (mach_port_t obj + for (i = 0; i < npages; i++) + pm_entries[i] |= PM_PAGINGOUT | PM_INIT; + +- if (!kcopy) +- for (i = 0; i < npages; i++) +- pm_entries[i] &= ~PM_INCORE; +- + /* If this write occurs while a lock is pending, record + it. We have to keep this list because a lock request + might come in while we do the I/O; in that case there +@@ -163,7 +179,10 @@ _pager_do_write_request (mach_port_t obj + for (i = 0; i < npages; i++) + { + if (omitdata & (1 << i)) +- continue; ++ { ++ notified[i] = 0; ++ continue; ++ } + + if (pm_entries[i] & PM_WRITEWAIT) + wakeup = 1; +@@ -179,14 +198,22 @@ _pager_do_write_request (mach_port_t obj + pm_entries[i] |= PM_INVALID; + + if (pm_entries[i] & PM_PAGEINWAIT) +- memory_object_data_supply (p->memobjcntl, +- offset + (vm_page_size * i), +- data + (vm_page_size * i), +- vm_page_size, 1, +- VM_PROT_NONE, 0, MACH_PORT_NULL); ++ { ++ memory_object_data_supply (p->memobjcntl, ++ offset + (vm_page_size * i), ++ data + (vm_page_size * i), ++ vm_page_size, 1, ++ VM_PROT_NONE, 0, MACH_PORT_NULL); ++ notified[i] = 0; ++ } + else +- munmap ((caddr_t) (data + (vm_page_size * i)), +- vm_page_size); ++ { ++ munmap ((caddr_t) (data + (vm_page_size * i)), ++ vm_page_size); ++ notified[i] = (! kcopy && p->notify_on_evict); ++ if (! kcopy) ++ pm_entries[i] &= ~PM_INCORE; ++ } + + pm_entries[i] &= ~(PM_PAGINGOUT | PM_PAGEINWAIT | PM_WRITEWAIT); + } +@@ -198,10 +225,29 @@ _pager_do_write_request (mach_port_t obj + if (wakeup) + condition_broadcast (&p->wakeup); + ++ notify: + _pager_allow_termination (p); +- + mutex_unlock (&p->interlock); + ++ for (i = 0; i < npages; i++) ++ { ++ assert (notified[i] == 0 || notified[i] == 1); ++ if (notified[i]) ++ { ++ short *pm_entry = &pm_entries[i]; ++ ++ /* Do notify user. */ ++ pager_notify_evict (p->upi, offset + (i * vm_page_size)); ++ ++ /* Clear any error that is left. Notification on eviction ++ is used only to change association of page, so any ++ error may no longer be valid. */ ++ mutex_lock (&p->interlock); ++ *pm_entry = SET_PM_ERROR (SET_PM_NEXTERROR (*pm_entry, 0), 0); ++ mutex_unlock (&p->interlock); ++ } ++ } ++ + ports_port_deref (p); + return 0; + +--- a/libpager/pager-create.c ++++ b/libpager/pager-create.c +@@ -22,7 +22,8 @@ struct pager * + pager_create (struct user_pager_info *upi, + struct port_bucket *bucket, + boolean_t may_cache, +- memory_object_copy_strategy_t copy_strategy) ++ memory_object_copy_strategy_t copy_strategy, ++ boolean_t notify_on_evict) + { + struct pager *p; + +@@ -38,6 +39,7 @@ pager_create (struct user_pager_info *up + p->attribute_requests = 0; + p->may_cache = may_cache; + p->copy_strategy = copy_strategy; ++ p->notify_on_evict = notify_on_evict; + p->memobjcntl = MACH_PORT_NULL; + p->memobjname = MACH_PORT_NULL; + p->seqno = -1; +--- a/libpager/pager.h ++++ b/libpager/pager.h +@@ -32,18 +32,21 @@ int pager_demuxer (mach_msg_header_t *in + mach_msg_header_t *outp); + + /* Create a new pager. The pager will have a port created for it +- (using libports, in BUCKET) and will be immediately ready +- to receive requests. U_PAGER will be provided to later calls to ++ (using libports, in BUCKET) and will be immediately ready to ++ receive requests. U_PAGER will be provided to later calls to + pager_find_address. The pager will have one user reference + created. MAY_CACHE and COPY_STRATEGY are the original values of +- those attributes as for memory_object_ready. Users may create +- references to pagers by use of the relevant ports library +- functions. On errors, return null and set errno. */ ++ those attributes as for memory_object_ready. If NOTIFY_ON_EVICT is ++ non-zero, pager_notify_evict user callback will be called when page ++ is evicted. Users may create references to pagers by use of the ++ relevant ports library functions. On errors, return null and set ++ errno. */ + struct pager * + pager_create (struct user_pager_info *u_pager, + struct port_bucket *bucket, + boolean_t may_cache, +- memory_object_copy_strategy_t copy_strategy); ++ memory_object_copy_strategy_t copy_strategy, ++ boolean_t notify_on_evict); + + /* Return the user_pager_info struct associated with a pager. */ + struct user_pager_info * +@@ -110,7 +113,7 @@ pager_offer_page (struct pager *pager, + /* Change the attributes of the memory object underlying pager PAGER. + Args MAY_CACHE and COPY_STRATEGY are as for + memory_object_change_atributes. Wait for the kernel to report completion +- off WAIT is set.*/ ++ iff WAIT is set. */ + void + pager_change_attributes (struct pager *pager, + boolean_t may_cache, +@@ -172,6 +175,18 @@ error_t + pager_unlock_page (struct user_pager_info *pager, + vm_offset_t address); + ++/* The user must define this function. It is used when you want be ++ able to change association of pages to backing store. To use it, ++ pass non-zero value in NOTIFY_ON_EVICT when pager is created with ++ pager_create. You can change association of page only when ++ pager_notify_evict has been called and you haven't touched page ++ content after that. Note there is a possibility that a page is ++ evicted, but user is not notified about that. The user should be ++ able to handle this case. */ ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page); ++ + /* The user must define this function. It should report back (in + *OFFSET and *SIZE the minimum valid address the pager will accept + and the size of the object. */ +--- a/libpager/priv.h ++++ b/libpager/priv.h +@@ -45,6 +45,7 @@ struct pager + + boolean_t may_cache; + memory_object_copy_strategy_t copy_strategy; ++ boolean_t notify_on_evict; + + /* Interface ports */ + memory_object_control_t memobjcntl; +--- a/storeio/pager.c ++++ b/storeio/pager.c +@@ -109,6 +109,13 @@ pager_unlock_page (struct user_pager_inf + return 0; + } + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ assert (!"unrequested notification on eviction"); ++} ++ + /* The user must define this function. It should report back (in + *OFFSET and *SIZE the minimum valid address the pager will accept + and the size of the object. */ +@@ -232,7 +239,7 @@ dev_get_memory_object (struct dev *dev, + { + dev->pager = + pager_create ((struct user_pager_info *)dev, pager_port_bucket, +- 1, MEMORY_OBJECT_COPY_DELAY); ++ 1, MEMORY_OBJECT_COPY_DELAY, 0); + if (dev->pager == NULL) + { + mutex_unlock (&dev->pager_lock); +--- a/tmpfs/pager-stubs.c ++++ b/tmpfs/pager-stubs.c +@@ -57,6 +57,14 @@ pager_unlock_page (struct user_pager_inf + return EIEIO; + } + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ abort(); ++} ++ ++ + /* The user must define this function. It should report back (in + *OFFSET and *SIZE the minimum valid address the pager will accept + and the size of the object. */ +--- a/ufs/pager.c ++++ b/ufs/pager.c +@@ -425,6 +425,13 @@ pager_unlock_page (struct user_pager_inf + return err; + } + ++void ++pager_notify_evict (struct user_pager_info *pager, ++ vm_offset_t page) ++{ ++ assert (!"unrequested notification on eviction"); ++} ++ + /* Implement the pager_report_extent callback from the pager library. See + <hurd/pager.h> for the interface description. */ + inline error_t +@@ -477,7 +484,7 @@ create_disk_pager (void) + upi->type = DISK; + upi->np = 0; + pager_bucket = ports_create_bucket (); +- diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, store->size, ++ diskfs_start_disk_pager (upi, pager_bucket, MAY_CACHE, 0, store->size, + &disk_image); + upi->p = diskfs_disk_pager; + } +@@ -570,7 +577,7 @@ diskfs_get_filemap (struct node *np, vm_ + upi->unlocked_pagein_length = 0; + diskfs_nref_light (np); + upi->p = pager_create (upi, pager_bucket, +- MAY_CACHE, MEMORY_OBJECT_COPY_DELAY); ++ MAY_CACHE, MEMORY_OBJECT_COPY_DELAY, 0); + if (upi->p == 0) + { + diskfs_nrele_light (np); diff --git a/debian/patches/ext2fs_nowait.patch b/debian/patches/ext2fs_nowait.patch new file mode 100644 index 00000000..061f9760 --- /dev/null +++ b/debian/patches/ext2fs_nowait.patch @@ -0,0 +1,154 @@ +Avoid waiting for disk I/O completion. This improves performance quite a bit, +and should not be less safe. + +diff --git a/ext2fs/dir.c b/ext2fs/dir.c +index 66d8c8a..f0f52f7 100644 +--- a/ext2fs/dir.c ++++ b/ext2fs/dir.c +@@ -690,7 +690,7 @@ diskfs_direnter_hard (struct node *dp, const char *name, struct node *np, + } + } + +- diskfs_file_update (dp, 1); ++ diskfs_file_update (dp, diskfs_synchronous); + + return 0; + } +@@ -727,7 +727,7 @@ diskfs_dirremove_hard (struct node *dp, struct dirstat *ds) + if (dp->dn->dirents && dp->dn->dirents[ds->idx] != -1) + dp->dn->dirents[ds->idx]--; + +- diskfs_file_update (dp, 1); ++ diskfs_file_update (dp, diskfs_synchronous); + + return 0; + } +@@ -753,7 +753,7 @@ diskfs_dirrewrite_hard (struct node *dp, struct node *np, struct dirstat *ds) + + munmap ((caddr_t) ds->mapbuf, ds->mapextent); + +- diskfs_file_update (dp, 1); ++ diskfs_file_update (dp, diskfs_synchronous); + + return 0; + } +diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c +index 077225b..2058a1c 100644 +--- a/ext2fs/truncate.c ++++ b/ext2fs/truncate.c +@@ -294,7 +294,7 @@ diskfs_truncate (struct node *node, off_t length) + node->dn_stat.st_size = length; + node->dn_set_mtime = 1; + node->dn_set_ctime = 1; +- diskfs_node_update (node, 1); ++ diskfs_node_update (node, diskfs_synchronous); + return 0; + } + +@@ -309,6 +309,7 @@ diskfs_truncate (struct node *node, off_t length) + { + diskfs_node_rdwr (node, (void *)zeroblock, length, block_size - offset, + 1, 0, 0); ++ /* Make sure that really happens to avoid leaks. */ + diskfs_file_update (node, 1); + } + +@@ -323,7 +324,7 @@ diskfs_truncate (struct node *node, off_t length) + node->dn_stat.st_size = length; + node->dn_set_mtime = 1; + node->dn_set_ctime = 1; +- diskfs_node_update (node, 1); ++ diskfs_node_update (node, diskfs_synchronous); + + err = diskfs_catch_exception (); + if (!err) +diff --git a/libdiskfs/dir-init.c b/libdiskfs/dir-init.c +index 2cba3a4..4efded0 100644 +--- a/libdiskfs/dir-init.c ++++ b/libdiskfs/dir-init.c +@@ -63,6 +63,6 @@ diskfs_init_dir (struct node *dp, struct node *pdp, struct protid *cred) + return err; + } + +- diskfs_node_update (dp, 1); ++ diskfs_node_update (dp, diskfs_synchronous); + return 0; + } +diff --git a/libdiskfs/dir-link.c b/libdiskfs/dir-link.c +index 7cc8863..df1bb6a 100644 +--- a/libdiskfs/dir-link.c ++++ b/libdiskfs/dir-link.c +@@ -101,7 +101,7 @@ diskfs_S_dir_link (struct protid *dircred, + } + np->dn_stat.st_nlink++; + np->dn_set_ctime = 1; +- diskfs_node_update (np, 1); ++ diskfs_node_update (np, diskfs_synchronous); + + /* Attach it */ + if (tnp) +diff --git a/libdiskfs/dir-rename.c b/libdiskfs/dir-rename.c +index 867e395..298669b 100644 +--- a/libdiskfs/dir-rename.c ++++ b/libdiskfs/dir-rename.c +@@ -164,7 +164,7 @@ diskfs_S_dir_rename (struct protid *fromcred, + } + fnp->dn_stat.st_nlink++; + fnp->dn_set_ctime = 1; +- diskfs_node_update (fnp, 1); ++ diskfs_node_update (fnp, diskfs_synchronous); + + if (tnp) + { +diff --git a/libdiskfs/dir-renamed.c b/libdiskfs/dir-renamed.c +index ce8f415..319a41a 100644 +--- a/libdiskfs/dir-renamed.c ++++ b/libdiskfs/dir-renamed.c +@@ -177,7 +177,7 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, const char *fromname, + } + fnp->dn_stat.st_nlink++; + fnp->dn_set_ctime = 1; +- diskfs_node_update (fnp, 1); ++ diskfs_node_update (fnp, diskfs_synchronous); + + if (tnp) + { +diff --git a/libdiskfs/file-set-trans.c b/libdiskfs/file-set-trans.c +index 26a19eb..c9b2c61 100644 +--- a/libdiskfs/file-set-trans.c ++++ b/libdiskfs/file-set-trans.c +@@ -196,7 +196,7 @@ diskfs_S_file_set_translator (struct protid *cred, + if (!error) + { + np->dn_stat.st_mode = newmode; +- diskfs_node_update (np, 1); ++ diskfs_node_update (np, diskfs_synchronous); + } + mutex_unlock (&np->lock); + return error; +diff --git a/libdiskfs/node-create.c b/libdiskfs/node-create.c +index 4a7d108..5b5e463 100644 +--- a/libdiskfs/node-create.c ++++ b/libdiskfs/node-create.c +@@ -131,7 +131,7 @@ diskfs_create_node (struct node *dir, + if (S_ISDIR (mode)) + err = diskfs_init_dir (np, dir, cred); + +- diskfs_node_update (np, 1); ++ diskfs_node_update (np, diskfs_synchronous); + + if (err) + { +diff --git a/libdiskfs/node-drop.c b/libdiskfs/node-drop.c +index f44966b..c3d32c9 100644 +--- a/libdiskfs/node-drop.c ++++ b/libdiskfs/node-drop.c +@@ -78,7 +78,7 @@ diskfs_drop_node (struct node *np) + np->dn_stat.st_mode = 0; + np->dn_stat.st_rdev = 0; + np->dn_set_ctime = np->dn_set_atime = 1; +- diskfs_node_update (np, 1); ++ diskfs_node_update (np, diskfs_synchronous); + diskfs_free_node (np, savemode); + } + else diff --git a/debian/patches/extern_inline_fix.patch b/debian/patches/extern_inline_fix.patch new file mode 100644 index 00000000..b9eacbff --- /dev/null +++ b/debian/patches/extern_inline_fix.patch @@ -0,0 +1,734 @@ +Use libc's __extern_inline which works properly according to optimization flags +--- + libdiskfs/diskfs.h | 17 ++++++---- + libpipe/pipe.h | 74 ++++++++++++++++++++++++++++++++------------ + libpipe/pq.h | 57 ++++++++++++++++++++++++++------- + libshouldbeinlibc/idvec.h | 29 ++++++++++++----- + libshouldbeinlibc/maptime.h | 13 ++++--- + libshouldbeinlibc/ugids.h | 25 ++++++++++---- + libstore/store.h | 13 ++++--- + libthreads/rwlock.h | 27 +++++++++++----- + 8 files changed, 184 insertions(+), 71 deletions(-) + +--- a/libdiskfs/diskfs.h ++++ b/libdiskfs/diskfs.h +@@ -27,10 +27,7 @@ + #include <hurd/fshelp.h> + #include <hurd/iohelp.h> + #include <idvec.h> +- +-#ifndef DISKFS_EXTERN_INLINE +-#define DISKFS_EXTERN_INLINE extern inline +-#endif ++#include <features.h> + + /* Each user port referring to a file points to one of these + (with the aid of the ports library). */ +@@ -781,10 +778,16 @@ error_t diskfs_start_protid (struct pero + the user to install is USER. */ + void diskfs_finish_protid (struct protid *cred, struct iouser *user); + ++extern struct protid * diskfs_begin_using_protid_port (file_t port); ++ ++extern void diskfs_end_using_protid_port (struct protid *cred); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Called by MiG to translate ports into struct protid *. + fsmutations.h arranges for this to happen for the io and + fs interfaces. */ +-DISKFS_EXTERN_INLINE struct protid * ++__extern_inline struct protid * + diskfs_begin_using_protid_port (file_t port) + { + return ports_lookup_port (diskfs_port_bucket, port, diskfs_protid_class); +@@ -793,13 +796,15 @@ diskfs_begin_using_protid_port (file_t p + /* Called by MiG after server routines have been run; this + balances begin_using_protid_port, and is arranged for the io + and fs interfaces by fsmutations.h. */ +-DISKFS_EXTERN_INLINE void ++__extern_inline void + diskfs_end_using_protid_port (struct protid *cred) + { + if (cred) + ports_port_deref (cred); + } + ++# endif /* Use extern inlines. */ ++ + /* Called when a protid CRED has no more references. (Because references\ + to protids are maintained by the port management library, this is + installed in the clean routines list.) The ports library will +--- a/libpipe/pipe.h ++++ b/libpipe/pipe.h +@@ -24,13 +24,10 @@ + #define EWOULDBLOCK EAGAIN /* XXX */ + + #include <cthreads.h> /* For conditions & mutexes */ ++#include <features.h> + + #include "pq.h" + +-#ifndef PIPE_EI +-#define PIPE_EI extern inline +-#endif +- + + /* A description of a class of pipes and how to operate on them. */ + struct pipe_class +@@ -107,9 +104,24 @@ struct pipe + /* Pipe flags. */ + #define PIPE_BROKEN 0x1 /* This pipe isn't connected. */ + ++ ++extern size_t pipe_readable (struct pipe *pipe, int data_only); ++ ++extern int pipe_is_readable (struct pipe *pipe, int data_only); ++ ++extern error_t pipe_wait_readable (struct pipe *pipe, int noblock, int data_only); ++ ++extern error_t pipe_select_readable (struct pipe *pipe, int data_only); ++ ++extern error_t pipe_wait_writable (struct pipe *pipe, int noblock); ++ ++extern error_t pipe_select_writable (struct pipe *pipe); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns the number of characters quickly readable from PIPE. If DATA_ONLY + is true, then `control' packets are ignored. */ +-PIPE_EI size_t ++__extern_inline size_t + pipe_readable (struct pipe *pipe, int data_only) + { + size_t readable = 0; +@@ -128,7 +140,7 @@ pipe_readable (struct pipe *pipe, int da + then `control' packets are ignored. Note that this is different than + (pipe_readable (PIPE) > 0) in the case where a control packet containing + only ports is present. */ +-PIPE_EI int ++__extern_inline int + pipe_is_readable (struct pipe *pipe, int data_only) + { + struct pq *pq = pipe->queue; +@@ -143,7 +155,7 @@ pipe_is_readable (struct pipe *pipe, int + this operation will return EWOULDBLOCK instead of blocking when no data is + immediately available. If DATA_ONLY is true, then `control' packets are + ignored. */ +-PIPE_EI error_t ++__extern_inline error_t + pipe_wait_readable (struct pipe *pipe, int noblock, int data_only) + { + while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN)) +@@ -160,7 +172,7 @@ pipe_wait_readable (struct pipe *pipe, i + returns once threads waiting using pipe_wait_readable have been woken and + given a chance to read, and if there is still data available thereafter. + If DATA_ONLY is true, then `control' packets are ignored. */ +-PIPE_EI error_t ++__extern_inline error_t + pipe_select_readable (struct pipe *pipe, int data_only) + { + while (! pipe_is_readable (pipe, data_only) && ! (pipe->flags & PIPE_BROKEN)) +@@ -172,7 +184,7 @@ pipe_select_readable (struct pipe *pipe, + /* Block until data can be written to PIPE. If NOBLOCK is true, then + EWOULDBLOCK is returned instead of blocking if this can't be done + immediately. */ +-PIPE_EI error_t ++__extern_inline error_t + pipe_wait_writable (struct pipe *pipe, int noblock) + { + size_t limit = pipe->write_limit; +@@ -193,7 +205,7 @@ pipe_wait_writable (struct pipe *pipe, i + /* Block until some data can be written to PIPE. This call only returns once + threads waiting using pipe_wait_writable have been woken and given a + chance to write, and if there is still space available thereafter. */ +-PIPE_EI error_t ++__extern_inline error_t + pipe_select_writable (struct pipe *pipe) + { + size_t limit = pipe->write_limit; +@@ -203,6 +215,8 @@ pipe_select_writable (struct pipe *pipe) + return 0; + } + ++# endif /* Use extern inlines. */ ++ + /* Creates a new pipe of class CLASS and returns it in RESULT. */ + error_t pipe_create (struct pipe_class *class, struct pipe **pipe); + +@@ -223,8 +237,28 @@ void _pipe_no_readers (struct pipe *pipe + should be locked. */ + void _pipe_no_writers (struct pipe *pipe); + ++extern void pipe_acquire_reader (struct pipe *pipe); ++ ++extern void pipe_acquire_writer (struct pipe *pipe); ++ ++extern void pipe_release_reader (struct pipe *pipe); ++ ++extern void pipe_release_writer (struct pipe *pipe); ++ ++extern void pipe_add_reader (struct pipe *pipe); ++ ++extern void pipe_add_writer (struct pipe *pipe); ++ ++extern void pipe_remove_reader (struct pipe *pipe); ++ ++extern void pipe_remove_writer (struct pipe *pipe); ++ ++extern void pipe_drain (struct pipe *pipe); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Lock PIPE and increment its readers count. */ +-PIPE_EI void ++__extern_inline void + pipe_acquire_reader (struct pipe *pipe) + { + mutex_lock (&pipe->lock); +@@ -233,7 +267,7 @@ pipe_acquire_reader (struct pipe *pipe) + } + + /* Lock PIPE and increment its writers count. */ +-PIPE_EI void ++__extern_inline void + pipe_acquire_writer (struct pipe *pipe) + { + mutex_lock (&pipe->lock); +@@ -243,7 +277,7 @@ pipe_acquire_writer (struct pipe *pipe) + + /* Decrement PIPE's (which should be locked) reader count and unlock it. If + there are no more refs to PIPE, it will be destroyed. */ +-PIPE_EI void ++__extern_inline void + pipe_release_reader (struct pipe *pipe) + { + if (--pipe->readers == 0) +@@ -254,7 +288,7 @@ pipe_release_reader (struct pipe *pipe) + + /* Decrement PIPE's (which should be locked) writer count and unlock it. If + there are no more refs to PIPE, it will be destroyed. */ +-PIPE_EI void ++__extern_inline void + pipe_release_writer (struct pipe *pipe) + { + if (--pipe->writers == 0) +@@ -264,7 +298,7 @@ pipe_release_writer (struct pipe *pipe) + } + + /* Increment PIPE's reader count. PIPE should be unlocked. */ +-PIPE_EI void ++__extern_inline void + pipe_add_reader (struct pipe *pipe) + { + pipe_acquire_reader (pipe); +@@ -272,7 +306,7 @@ pipe_add_reader (struct pipe *pipe) + } + + /* Increment PIPE's writer count. PIPE should be unlocked. */ +-PIPE_EI void ++__extern_inline void + pipe_add_writer (struct pipe *pipe) + { + pipe_acquire_writer (pipe); +@@ -281,7 +315,7 @@ pipe_add_writer (struct pipe *pipe) + + /* Decrement PIPE's (which should be unlocked) reader count and unlock it. If + there are no more refs to PIPE, it will be destroyed. */ +-PIPE_EI void ++__extern_inline void + pipe_remove_reader (struct pipe *pipe) + { + mutex_lock (&pipe->lock); +@@ -290,7 +324,7 @@ pipe_remove_reader (struct pipe *pipe) + + /* Decrement PIPE's (which should be unlocked) writer count and unlock it. If + there are no more refs to PIPE, it will be destroyed. */ +-PIPE_EI void ++__extern_inline void + pipe_remove_writer (struct pipe *pipe) + { + mutex_lock (&pipe->lock); +@@ -298,12 +332,14 @@ pipe_remove_writer (struct pipe *pipe) + } + + /* Empty out PIPE of any data. PIPE should be locked. */ +-PIPE_EI void ++__extern_inline void + pipe_drain (struct pipe *pipe) + { + pq_drain (pipe->queue); + } + ++# endif /* Use extern inlines. */ ++ + /* Writes up to LEN bytes of DATA, to PIPE, which should be locked, and + returns the amount written in AMOUNT. If present, the information in + CONTROL & PORTS is written in a preceding control packet. If an error is +--- a/libpipe/pq.h ++++ b/libpipe/pq.h +@@ -25,10 +25,7 @@ + #include <stddef.h> /* for size_t */ + #include <string.h> + #include <mach/mach.h> +- +-#ifndef PQ_EI +-#define PQ_EI extern inline +-#endif ++#include <features.h> + + + struct packet +@@ -70,13 +67,19 @@ error_t packet_set_ports (struct packet + /* If PACKET has any ports, deallocates them. */ + void packet_dealloc_ports (struct packet *packet); + ++extern size_t packet_readable (struct packet *packet); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns the number of bytes of data in PACKET. */ +-PQ_EI size_t ++__extern_inline size_t + packet_readable (struct packet *packet) + { + return packet->buf_end - packet->buf_start; + } + ++# endif /* Use extern inlines. */ ++ + /* Append the bytes in DATA, of length DATA_LEN, to what's already in PACKET, + and return the amount appended in AMOUNT if that's not the null pointer. */ + error_t packet_write (struct packet *packet, +@@ -94,14 +97,20 @@ error_t packet_read (struct packet *pack + error_t packet_read_ports (struct packet *packet, + mach_port_t **ports, size_t *num_ports); + ++extern void packet_read_source (struct packet *packet, void **source); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Return the source addressd in PACKET in SOURCE, deallocating it from + PACKET. */ +-PQ_EI void ++__extern_inline void + packet_read_source (struct packet *packet, void **source) + { + *source = packet->source; + packet->source = 0; + } ++ ++# endif /* Use extern inlines. */ + + /* The packet size above which we start to do things differently to avoid + copying around data. */ +@@ -125,9 +134,17 @@ int packet_extend (struct packet *packet + returned. */ + error_t packet_realloc (struct packet *packet, size_t new_len); + ++extern int packet_fit (struct packet *packet, size_t amount); ++ ++extern error_t packet_ensure (struct packet *packet, size_t amount); ++ ++extern int packet_ensure_efficiently (struct packet *packet, size_t amount); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Try to make space in PACKET for AMOUNT more bytes without growing the + buffer, returning true if we could do it. */ +-PQ_EI int ++__extern_inline int + packet_fit (struct packet *packet, size_t amount) + { + char *buf = packet->buf, *end = packet->buf_end; +@@ -159,7 +176,7 @@ packet_fit (struct packet *packet, size_ + + /* Make sure that PACKET has room for at least AMOUNT more bytes, or return + the reason why not. */ +-PQ_EI error_t ++__extern_inline error_t + packet_ensure (struct packet *packet, size_t amount) + { + if (! packet_fit (packet, amount)) +@@ -176,7 +193,7 @@ packet_ensure (struct packet *packet, si + it can be done efficiently, e.g., the packet can be grown in place, rather + than moving the contents (or there is little enough data so that copying + it is OK). True is returned if room was made, false otherwise. */ +-PQ_EI int ++__extern_inline int + packet_ensure_efficiently (struct packet *packet, size_t amount) + { + if (! packet_fit (packet, amount)) +@@ -189,6 +206,8 @@ packet_ensure_efficiently (struct packet + } + return 0; + } ++ ++# endif /* Use extern inlines. */ + + struct pq + { +@@ -201,10 +220,14 @@ struct pq + the packet, or deallocated by calling pipe_dealloc_addr. */ + struct packet *pq_queue (struct pq *pq, unsigned type, void *source); + ++extern struct packet * pq_tail (struct pq *pq, unsigned type, void *source); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns the tail of the packet queue PQ, which may mean pushing a new + packet if TYPE and SOURCE do not match the current tail, or this is the + first packet. */ +-PQ_EI struct packet * ++__extern_inline struct packet * + pq_tail (struct pq *pq, unsigned type, void *source) + { + struct packet *tail = pq->tail; +@@ -214,16 +237,24 @@ pq_tail (struct pq *pq, unsigned type, v + return tail; + } + ++# endif /* Use extern inlines. */ ++ + /* Remove the first packet (if any) in PQ, deallocating any resources it + holds. True is returned if a packet was found, false otherwise. */ + int pq_dequeue (struct pq *pq); + ++extern struct packet * pq_head (struct pq *pq, unsigned type, void *source); ++ ++extern struct packet * pq_next (struct pq *pq, unsigned type, void *source); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns the next available packet in PQ, without removing it from the + queue, or NULL if there is none, or the next packet isn't appropriate. + A packet is inappropriate if SOURCE is non-NULL its source field doesn't + match it, or TYPE is non-NULL and the packet's type field doesn't match + it. */ +-PQ_EI struct packet * ++__extern_inline struct packet * + pq_head (struct pq *pq, unsigned type, void *source) + { + struct packet *head = pq->head; +@@ -237,7 +268,7 @@ pq_head (struct pq *pq, unsigned type, v + } + + /* The same as pq_head, but first discards the head of the queue. */ +-PQ_EI struct packet * ++__extern_inline struct packet * + pq_next (struct pq *pq, unsigned type, void *source) + { + if (!pq->head) +@@ -246,6 +277,8 @@ pq_next (struct pq *pq, unsigned type, v + return pq_head (pq, type, source); + } + ++# endif /* Use extern inlines. */ ++ + /* Dequeues all packets in PQ. */ + void pq_drain (struct pq *pq); + +--- a/libshouldbeinlibc/idvec.h ++++ b/libshouldbeinlibc/idvec.h +@@ -24,10 +24,7 @@ + #include <hurd/hurd_types.h> + #include <errno.h> + #include <string.h> +- +-#ifndef IDVEC_EI +-#define IDVEC_EI extern inline +-#endif ++#include <features.h> + + struct idvec + { +@@ -50,22 +47,30 @@ void idvec_free_wrapper (struct idvec *i + /* Free IDVEC and any storage associated with it. */ + void idvec_free (struct idvec *idvec); + ++extern void idvec_clear (struct idvec *idvec); ++ ++extern int idvec_is_empty (const struct idvec *idvec); ++ ++extern int idvec_equal (const struct idvec *idvec1, const struct idvec *idvec2); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Mark IDVEC as not containing any ids. */ +-IDVEC_EI void ++__extern_inline void + idvec_clear (struct idvec *idvec) + { + idvec->num = 0; + } + + /* Returns true if IDVEC contains no ids. */ +-IDVEC_EI int ++__extern_inline int + idvec_is_empty (const struct idvec *idvec) + { + return idvec->num == 0; + } + + /* Return true if IDVEC1 has contents identical to IDVEC2. */ +-IDVEC_EI int ++__extern_inline int + idvec_equal (const struct idvec *idvec1, const struct idvec *idvec2) + { + size_t num = idvec1->num; +@@ -74,6 +79,8 @@ idvec_equal (const struct idvec *idvec1, + || memcmp (idvec1->ids, idvec2->ids, num * sizeof *idvec1->ids) == 0); + } + ++# endif /* Use extern inlines. */ ++ + /* Ensure that IDVEC has enough spaced allocated to hold NUM ids, thus + ensuring that any subsequent ids added won't return a memory allocation + error unless it would result in more ids that NUM. ENOMEM is returned if +@@ -87,13 +94,19 @@ error_t idvec_grow (struct idvec *idvec, + /* Returns true if IDVEC contains ID, at or after position POS. */ + int idvec_tail_contains (const struct idvec *idvec, unsigned pos, uid_t id); + ++extern int idvec_contains (const struct idvec *idvec, uid_t id); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns true if IDVEC contains ID. */ +-IDVEC_EI int ++__extern_inline int + idvec_contains (const struct idvec *idvec, uid_t id) + { + return idvec_tail_contains (idvec, 0, id); + } + ++# endif /* Use extern inlines. */ ++ + /* Insert ID into IDVEC at position POS, returning ENOMEM if there wasn't + enough memory, or 0. */ + error_t idvec_insert (struct idvec *idvec, unsigned pos, uid_t id); +--- a/libshouldbeinlibc/maptime.h ++++ b/libshouldbeinlibc/maptime.h +@@ -21,13 +21,10 @@ + #ifndef __MAPTIME_H__ + #define __MAPTIME_H__ + +-#ifndef MAPTIME_EI +-#define MAPTIME_EI extern inline +-#endif +- + #include <mach/time_value.h> + #include <sys/time.h> + #include <errno.h> ++#include <features.h> + + /* Return the mach mapped time page in MTIME. If USE_MACH_DEV is false, then + the hurd time device DEV_NAME, or "/dev/time" if DEV_NAME is 0, is +@@ -37,8 +34,12 @@ + error_t maptime_map (int use_mach_dev, char *dev_name, + volatile struct mapped_time_value **mtime); + ++extern void maptime_read (volatile struct mapped_time_value *mtime, struct timeval *tv); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Read the current time from MTIME into TV. This should be very fast. */ +-MAPTIME_EI void ++__extern_inline void + maptime_read (volatile struct mapped_time_value *mtime, struct timeval *tv) + { + do +@@ -49,4 +50,6 @@ maptime_read (volatile struct mapped_tim + while (tv->tv_sec != mtime->check_seconds); + } + ++# endif /* Use extern inlines. */ ++ + #endif /* __MAPTIME_H__ */ +--- a/libshouldbeinlibc/ugids.h ++++ b/libshouldbeinlibc/ugids.h +@@ -23,10 +23,7 @@ + + #include <stdlib.h> /* For inline function stuff. */ + #include <idvec.h> +- +-#ifndef UGIDS_EI +-#define UGIDS_EI extern inline +-#endif ++#include <features.h> + + /* A structure holding a set of the common various types of ids. */ + struct ugids +@@ -47,8 +44,18 @@ struct ugids + /* Return a new ugids structure, or 0 if an allocation error occurs. */ + struct ugids *make_ugids (); + ++extern void ugids_fini (struct ugids *ugids); ++ ++extern void ugids_free (struct ugids *ugids); ++ ++extern int ugids_is_empty (const struct ugids *ugids); ++ ++extern int ugids_equal (const struct ugids *ugids1, const struct ugids *ugids2); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Free all resources used by UGIDS except UGIDS itself. */ +-UGIDS_EI void ++__extern_inline void + ugids_fini (struct ugids *ugids) + { + idvec_fini (&ugids->eff_uids); +@@ -60,7 +67,7 @@ ugids_fini (struct ugids *ugids) + } + + /* Free all resources used by UGIDS. */ +-UGIDS_EI void ++__extern_inline void + ugids_free (struct ugids *ugids) + { + ugids_fini (ugids); +@@ -68,7 +75,7 @@ ugids_free (struct ugids *ugids) + } + + /* Return true if UGIDS contains no ids. */ +-UGIDS_EI int ++__extern_inline int + ugids_is_empty (const struct ugids *ugids) + { + /* We needn't test the imp_*_gids vectors because they are subsets of the +@@ -81,7 +88,7 @@ ugids_is_empty (const struct ugids *ugid + } + + /* Free all resources used by UGIDS except UGIDS itself. */ +-UGIDS_EI int ++__extern_inline int + ugids_equal (const struct ugids *ugids1, const struct ugids *ugids2) + { + return +@@ -93,6 +100,8 @@ ugids_equal (const struct ugids *ugids1, + && idvec_equal (&ugids1->imp_avail_gids, &ugids2->imp_avail_gids); + } + ++# endif /* Use extern inlines. */ ++ + /* Add all ids in NEW to UGIDS. */ + error_t ugids_merge (struct ugids *ugids, const struct ugids *new); + +--- a/libstore/store.h ++++ b/libstore/store.h +@@ -33,10 +33,7 @@ + #include <mach.h> + #include <device/device.h> + #include <hurd/hurd_types.h> +- +-#ifndef STORE_EI +-#define STORE_EI extern inline +-#endif ++#include <features.h> + + + /* Type for addresses inside the store. */ +@@ -270,9 +267,13 @@ error_t store_set_child_flags (struct st + STORE's flags. */ + error_t store_clear_child_flags (struct store *store, int flags); + ++extern int store_is_securely_returnable (struct store *store, int open_flags); ++ ++# ifdef __USE_EXTERN_INLINES ++ + /* Returns true if STORE can safely be returned to a user who has accessed it + via a node using OPEN_FLAGS, without compromising security. */ +-STORE_EI int ++__extern_inline int + store_is_securely_returnable (struct store *store, int open_flags) + { + int flags = store->flags; +@@ -283,6 +284,8 @@ store_is_securely_returnable (struct sto + || (flags & STORE_HARD_READONLY))); + } + ++# endif /* Use extern inlines. */ ++ + /* Fills in the values of the various fields in STORE that are derivable from + the set of runs & the block size. */ + void _store_derive (struct store *store); +--- a/libthreads/rwlock.h ++++ b/libthreads/rwlock.h +@@ -21,6 +21,7 @@ + + #include <cthreads.h> + #include <assert.h> ++#include <features.h> + + struct rwlock + { +@@ -31,12 +32,20 @@ struct rwlock + int readers_waiting; + }; + +-#ifndef RWLOCK_EI +-#define RWLOCK_EI extern inline +-#endif ++extern void rwlock_reader_lock (struct rwlock *lock); ++ ++extern void rwlock_writer_lock (struct rwlock *lock); ++ ++extern void rwlock_reader_unlock (struct rwlock *lock); ++ ++extern void rwlock_writer_unlock (struct rwlock *lock); ++ ++extern void rwlock_init (struct rwlock *lock); ++ ++# ifdef __USE_EXTERN_INLINES + + /* Get a reader lock on reader-writer lock LOCK for disknode DN */ +-RWLOCK_EI void ++__extern_inline void + rwlock_reader_lock (struct rwlock *lock) + { + mutex_lock (&lock->master); +@@ -53,7 +62,7 @@ rwlock_reader_lock (struct rwlock *lock) + } + + /* Get a writer lock on reader-writer lock LOCK for disknode DN */ +-RWLOCK_EI void ++__extern_inline void + rwlock_writer_lock (struct rwlock *lock) + { + mutex_lock (&lock->master); +@@ -70,7 +79,7 @@ rwlock_writer_lock (struct rwlock *lock) + } + + /* Release a reader lock on reader-writer lock LOCK for disknode DN */ +-RWLOCK_EI void ++__extern_inline void + rwlock_reader_unlock (struct rwlock *lock) + { + mutex_lock (&lock->master); +@@ -82,7 +91,7 @@ rwlock_reader_unlock (struct rwlock *loc + } + + /* Release a writer lock on reader-writer lock LOCK for disknode DN */ +-RWLOCK_EI void ++__extern_inline void + rwlock_writer_unlock (struct rwlock *lock) + { + mutex_lock (&lock->master); +@@ -94,7 +103,7 @@ rwlock_writer_unlock (struct rwlock *loc + } + + /* Initialize reader-writer lock LOCK */ +-RWLOCK_EI void ++__extern_inline void + rwlock_init (struct rwlock *lock) + { + mutex_init (&lock->master); +@@ -104,6 +113,8 @@ rwlock_init (struct rwlock *lock) + lock->writers_waiting = 0; + } + ++# endif /* Use extern inlines. */ ++ + #define RWLOCK_INITIALIZER \ + { MUTEX_INITIALIZER, CONDITION_INITIALIZER, 0, 0, 0 } + diff --git a/debian/patches/hurd_console_startup.patch b/debian/patches/hurd_console_startup.patch new file mode 100644 index 00000000..8e9301c8 --- /dev/null +++ b/debian/patches/hurd_console_startup.patch @@ -0,0 +1,32 @@ +Automatically startup the hurd console when enabled. +--- + daemons/runsystem.sh | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +--- a/daemons/runsystem.sh ++++ b/daemons/runsystem.sh +@@ -127,10 +127,24 @@ while : ; do + trap "kill -$sig \${runttys_pid}" $sig + done + ++ # Touch the first tty so that the Hurd console is certain to pick it ++ # and not some random other tty. ++ touch /dev/tty1 ++ + # This program reads /etc/ttys and starts the programs it says to. + ${RUNTTYS} & + runttys_pid=$! + ++ # Startup the Hurd console if configured. ++ if [ -e /etc/default/hurd-console ]; then ++ unset DISPLAY KBD KBD_REPEAT MOUSE MOUSE_REPEAT SPEAKER ++ . /etc/default/hurd-console ++ fi ++ if [ "$ENABLE" = "true" ]; then ++ console ${DISPLAY} ${KBD} ${KBD_REPEAT} \ ++ ${SPEAKER} ${MOUSE} ${MOUSE_REPEAT} -d current_vcs -c /dev/vcs ++ fi ++ + # Wait for runttys to die, meanwhile handling trapped signals. + wait + diff --git a/debian/patches/init_try_runsystem.gnu.patch b/debian/patches/init_try_runsystem.gnu.patch new file mode 100644 index 00000000..817a6d84 --- /dev/null +++ b/debian/patches/init_try_runsystem.gnu.patch @@ -0,0 +1,75 @@ +Also try runsystem.gnu +--- + daemons/console-run.c | 7 +++++++ + init/init.c | 24 ++++++++++++++++++++---- + 2 files changed, 27 insertions(+), 4 deletions(-) + +--- a/init/init.c ++++ b/init/init.c +@@ -1082,10 +1082,12 @@ start_child (const char *prog, char **pr + static void + launch_something (const char *why) + { ++ file_t something; + static unsigned int try; + static const char *const tries[] = + { + "/libexec/runsystem", ++ "/libexec/runsystem.gnu", + _PATH_BSHELL, + "/bin/shd", /* XXX */ + }; +@@ -1093,12 +1095,26 @@ launch_something (const char *why) + if (why) + error (0, 0, "%s %s", tries[try - 1], why); + +- if (try == 0 && start_child (tries[try++], &global_argv[1]) == 0) +- return; ++ something = file_name_lookup (tries[try], O_EXEC, 0); ++ if (something != MACH_PORT_NULL) ++ { ++ mach_port_deallocate (mach_task_self (), something); ++ if (try == 0 && start_child (tries[try++], &global_argv[1]) == 0) ++ return; ++ } ++ else ++ try++; + + while (try < sizeof tries / sizeof tries[0]) +- if (start_child (tries[try++], NULL) == 0) +- return; ++ { ++ something = file_name_lookup (tries[try], O_EXEC, 0); ++ if (something != MACH_PORT_NULL) ++ { ++ mach_port_deallocate (mach_task_self (), something); ++ if (start_child (tries[try++], NULL) == 0) ++ return; ++ } ++ } + + crash_system (); + } +--- a/daemons/console-run.c ++++ b/daemons/console-run.c +@@ -49,6 +49,7 @@ int + main (int argc, char **argv) + { + mach_port_t consdev = get_console (); ++ mach_port_t runsystem; + char *consname; + + if (consdev == MACH_PORT_NULL) +@@ -62,6 +63,12 @@ main (int argc, char **argv) + if (argc < 2) + error (1, 0, "Usage: %s PROGRAM [ARG...]", program_invocation_short_name); + ++ /* Check whether runsystem exists before opening a console for it. */ ++ runsystem = file_name_lookup (argv[1], O_RDONLY, 0); ++ if (runsystem == MACH_PORT_NULL) ++ error (127, errno, "cannot open file `%s' for execution", argv[1]); ++ mach_port_deallocate (mach_task_self (), runsystem); ++ + if (open_console (&consname)) + setenv ("FALLBACK_CONSOLE", consname, 1); + diff --git a/debian/patches/install-msgids.diff b/debian/patches/install-msgids.diff new file mode 100644 index 00000000..305e0e0d --- /dev/null +++ b/debian/patches/install-msgids.diff @@ -0,0 +1,36 @@ +2005-08-25 Alfred M. Szmidt <ams@gnu.org> + + * Makefile (MSGIDS): New variable. + (all, install-msgids, $(datadir)/msgids): New targets. + (install): Specify install-header and install-msgids as + prerequisites. + +--- + hurd/Makefile | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +--- a/hurd/Makefile ++++ b/hurd/Makefile +@@ -22,15 +22,20 @@ DIST_FILES = subsystems $(notdir $(hdrs) + + INSTHDRS = hurd_types.h version.h ioctl_types.h paths.h shared.h console.h \ + $(notdir $(wildcard $(srcdir)/*.defs)) ++MSGIDS := hurd.msgids $(patsubst %.defs,%.msgids,$(filter %.defs,$(INSTHDRS))) + + include ../Makeconf + +-install-headers install: $(includedir)/hurd \ ++all: $(MSGIDS) ++ ++install: install-msgids install-headers ++install-headers: $(includedir)/hurd \ + $(addprefix $(includedir)/hurd/,$(INSTHDRS)) ++install-msgids: $(MSGIDS) $(datadir)/msgids; $(INSTALL_DATA) $^ + + $(includedir)/hurd/%: $(srcdir)/%; $(INSTALL_DATA) $< $@ + +-$(includedir)/hurd:;mkdir -p $@ ++$(datadir)/msgids $(includedir)/hurd:;mkdir -p $@ + + %.msgids: $(srcdir)/%.defs + if grep -q '^subsystem' $<; \ diff --git a/debian/patches/libdiskfs_self-reauth.patch b/debian/patches/libdiskfs_self-reauth.patch new file mode 100644 index 00000000..b3e048b2 --- /dev/null +++ b/debian/patches/libdiskfs_self-reauth.patch @@ -0,0 +1,32 @@ +"RPC to self with rendez-vous leading to duplicate port destroy" + +http://lists.gnu.org/archive/html/bug-hurd/2011-03/msg00045.html + +diff --git a/libfshelp/fetch-root.c b/libfshelp/fetch-root.c +index 54d3c0c..6585052 100644 +--- a/libfshelp/fetch-root.c ++++ b/libfshelp/fetch-root.c +@@ -79,7 +79,9 @@ fshelp_fetch_root (struct transbox *box, void *cookie, + if (err) + ret = MACH_PORT_NULL; + +- mach_port_destroy (mach_task_self (), rend); ++ /* crdir could be ourselves, and thus diskfs_S_io_reauthenticate ++ * would get the same name, so don't _destroy_ it !! */ ++ mach_port_mod_refs (mach_task_self (), rend, MACH_PORT_RIGHT_RECEIVE, -1); + + return ret; + } +diff --git a/libshouldbeinlibc/exec-reauth.c b/libshouldbeinlibc/exec-reauth.c +index dd267ef..12b34fc 100644 +--- a/libshouldbeinlibc/exec-reauth.c ++++ b/libshouldbeinlibc/exec-reauth.c +@@ -59,7 +59,7 @@ exec_reauth (auth_t auth, int secure, int must_reauth, + if (!err) + err = auth_user_authenticate (auth, ref, MACH_MSG_TYPE_MAKE_SEND, + &newport); +- mach_port_destroy (mach_task_self (), ref); ++ mach_port_mod_refs (mach_task_self (), ref, MACH_PORT_RIGHT_RECEIVE, -1); + if (err) + { + if (must_reauth) diff --git a/debian/patches/libdiskfs_sync.patch b/debian/patches/libdiskfs_sync.patch new file mode 100644 index 00000000..19e45170 --- /dev/null +++ b/debian/patches/libdiskfs_sync.patch @@ -0,0 +1,16 @@ +Set diskfs stores as readonly on shutdown before enabling RPCs again. + +diff --git a/libdiskfs/init-startup.c b/libdiskfs/init-startup.c +index bf1acf2..700a26e 100644 +--- a/libdiskfs/init-startup.c ++++ b/libdiskfs/init-startup.c +@@ -148,6 +148,9 @@ diskfs_S_startup_dosync (mach_port_t handle) + diskfs_set_hypermetadata (1, 1); + _diskfs_diskdirty = 0; + ++ diskfs_readonly = 1; ++ diskfs_readonly_changed (1); ++ + ports_resume_class_rpcs (diskfs_protid_class); + } + diff --git a/debian/patches/libpager_deadlock.patch b/debian/patches/libpager_deadlock.patch new file mode 100644 index 00000000..ea2d9087 --- /dev/null +++ b/debian/patches/libpager_deadlock.patch @@ -0,0 +1,20 @@ +See http://lists.gnu.org/archive/html/bug-hurd/2010-03/msg00127.html +for the story. This should be completely safe, but Sergio believes +memory_object_lock_request shouldn't actually block. + +diff --git a/libpager/lock-object.c b/libpager/lock-object.c +index d108666..d8d4a1b 100644 +--- a/libpager/lock-object.c ++++ b/libpager/lock-object.c +@@ -65,9 +65,11 @@ _pager_lock_object (struct pager *p, + } + } + ++ mutex_unlock (&p->interlock); + memory_object_lock_request (p->memobjcntl, offset, size, should_return, + should_flush, lock_value, + sync ? p->port.port_right : MACH_PORT_NULL); ++ mutex_lock (&p->interlock); + + if (sync) + { diff --git a/debian/patches/libpager_update_seqno.patch b/debian/patches/libpager_update_seqno.patch new file mode 100644 index 00000000..6246e8a1 --- /dev/null +++ b/debian/patches/libpager_update_seqno.patch @@ -0,0 +1,140 @@ +2005-08-10 Sergio Lopez <koro@sinrega.org> + + * seqnos.c (_pager_stubs_update_seqno): New function. + * priv.h (_pager_stubs_update_seqno): New function. + + * notify-stubs.c (_pager_do_seqnos_mach_notify_port_deleted): + Call _pager_stubs_update_seqno to properly update seqno. + (_pager_do_seqnos_mach_notify_msg_accepted): Likewise. + (_pager_do_seqnos_mach_notify_port_destroyed): Likewise. + (_pager_do_seqnos_mach_notify_send_once): Likewise. + (_pager_do_seqnos_mach_notify_dead_name): Likewise. + * stubs.c (_pager_seqnos_memory_object_data_write): Likewise. + (_pager_seqnos_memory_object_supply_completed): Likewise. + +--- + libpager/notify-stubs.c | 6 ++++++ + libpager/priv.h | 1 + + libpager/seqnos.c | 22 ++++++++++++++++++++++ + libpager/stubs.c | 9 +++++++++ + 4 files changed, 38 insertions(+) + +--- a/libpager/notify-stubs.c ++++ b/libpager/notify-stubs.c +@@ -18,6 +18,7 @@ + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + ++#include "priv.h" + #include "notify_S.h" + #include <errno.h> + +@@ -29,6 +30,7 @@ _pager_do_seqnos_mach_notify_port_delete + mach_port_t name + __attribute__ ((unused))) + { ++ _pager_stubs_update_seqno (notify, seqno); + return 0; + } + +@@ -40,6 +42,7 @@ _pager_do_seqnos_mach_notify_msg_accepte + mach_port_t name + __attribute__ ((unused))) + { ++ _pager_stubs_update_seqno (notify, seqno); + return 0; + } + +@@ -51,6 +54,7 @@ _pager_do_seqnos_mach_notify_port_destro + mach_port_t name + __attribute__ ((unused))) + { ++ _pager_stubs_update_seqno (notify, seqno); + return 0; + } + +@@ -60,6 +64,7 @@ _pager_do_seqnos_mach_notify_send_once ( + mach_port_seqno_t seqno + __attribute__ ((unused))) + { ++ _pager_stubs_update_seqno (notify, seqno); + return 0; + } + +@@ -71,5 +76,6 @@ _pager_do_seqnos_mach_notify_dead_name ( + mach_port_t name + __attribute__ ((unused))) + { ++ _pager_stubs_update_seqno (notify, seqno); + return 0; + } +--- a/libpager/priv.h ++++ b/libpager/priv.h +@@ -134,6 +134,7 @@ struct port_class *_pager_class; + + void _pager_wait_for_seqno (struct pager *, int); + void _pager_release_seqno (struct pager *, int); ++void _pager_stubs_update_seqno (mach_port_t, int); + void _pager_block_termination (struct pager *); + void _pager_allow_termination (struct pager *); + error_t _pager_pagemap_resize (struct pager *, vm_address_t); +--- a/libpager/seqnos.c ++++ b/libpager/seqnos.c +@@ -47,3 +47,25 @@ _pager_release_seqno (struct pager *p, + condition_broadcast (&p->wakeup); + } + } ++ ++ ++/* This function is called by stub functions to properly update ++ seqno. */ ++void ++_pager_stubs_update_seqno (mach_port_t object, ++ int seqno) ++{ ++ struct pager *p; ++ ++ p = ports_lookup_port (0, object, _pager_class); ++ if (p) ++ { ++ mutex_lock (&p->interlock); ++ _pager_wait_for_seqno (p, seqno); ++ _pager_release_seqno (p, seqno); ++ mutex_unlock (&p->interlock); ++ ++ ports_port_deref (p); ++ } ++} ++ +--- a/libpager/stubs.c ++++ b/libpager/stubs.c +@@ -29,6 +29,9 @@ _pager_seqnos_memory_object_copy (mach_p + mach_port_t new) + { + printf ("m_o_copy called\n"); ++ ++ _pager_stubs_update_seqno (old, seq); ++ + return EOPNOTSUPP; + } + +@@ -41,6 +44,9 @@ _pager_seqnos_memory_object_data_write ( + vm_size_t data_cnt) + { + printf ("m_o_data_write called\n"); ++ ++ _pager_stubs_update_seqno (old, seq); ++ + return EOPNOTSUPP; + } + +@@ -54,6 +60,9 @@ _pager_seqnos_memory_object_supply_compl + vm_offset_t err_off) + { + printf ("m_o_supply_completed called\n"); ++ ++ _pager_stubs_update_seqno (obj, seq); ++ + return EOPNOTSUPP; + } + diff --git a/debian/patches/libports_stability.patch b/debian/patches/libports_stability.patch new file mode 100644 index 00000000..84edc491 --- /dev/null +++ b/debian/patches/libports_stability.patch @@ -0,0 +1,18 @@ +Ideally we should be able to time out and see translators go away automatically, +however it makes all threads often wake at the same time and overload Mach. + +--- + libports/manage-multithread.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/libports/manage-multithread.c ++++ b/libports/manage-multithread.c +@@ -157,6 +157,8 @@ ports_manage_port_operations_multithread + return 0; + } + ++ thread_timeout = global_timeout = 0; /* XXX */ ++ + nreqthreads = 1; + totalthreads = 1; + thread_function (1); diff --git a/debian/patches/libpthread_fix.patch b/debian/patches/libpthread_fix.patch new file mode 100644 index 00000000..56e03850 --- /dev/null +++ b/debian/patches/libpthread_fix.patch @@ -0,0 +1,75 @@ +Temporary patch from Thomas Schwinge to fix libpthread bugs. + +--- + libpthread/sysdeps/mach/hurd/pt-init-specific.c | 29 ++++++++++++++++++++++++ + libpthread/sysdeps/mach/pt-thread-dealloc.c | 2 + + libpthread/sysdeps/mach/pt-thread-halt.c | 19 ++++++++++++++- + 3 files changed, 48 insertions(+), 2 deletions(-) + +--- a/libpthread/sysdeps/mach/pt-thread-dealloc.c ++++ b/libpthread/sysdeps/mach/pt-thread-dealloc.c +@@ -38,4 +38,6 @@ __pthread_thread_dealloc (struct __pthre + assert. */ + __mach_port_destroy (__mach_task_self (), + thread->wakeupmsg.msgh_remote_port); ++ ++ thread->have_kernel_resources = 0; + } +--- a/libpthread/sysdeps/mach/pt-thread-halt.c ++++ b/libpthread/sysdeps/mach/pt-thread-halt.c +@@ -32,6 +32,21 @@ + void + __pthread_thread_halt (struct __pthread *thread) + { +- error_t err = __thread_terminate (thread->kernel_thread); +- assert_perror (err); ++ if (thread->have_kernel_resources) ++ { ++ if (thread == _pthread_self ()) ++ { ++ while (1) ++ { ++ error_t err = __thread_suspend (thread->kernel_thread); ++ assert_perror (err); ++ assert (! "Failed to suspend self."); ++ } ++ } ++ else ++ { ++ error_t err = __thread_terminate (thread->kernel_thread); ++ assert_perror (err); ++ } ++ } + } +--- /dev/null ++++ b/libpthread/sysdeps/mach/hurd/pt-init-specific.c +@@ -0,0 +1,29 @@ ++/* __pthread_init_specific. Mach version. ++ Copyright (C) 2002, 2009 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Library General Public License as ++ published by the Free Software Foundation; either version 2 of the ++ License, or (at your option) any later version. ++ ++ The GNU C Library is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ Library General Public License for more details. ++ ++ You should have received a copy of the GNU Library General Public ++ License along with the GNU C Library; see the file COPYING.LIB. If not, ++ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ++ Boston, MA 02111-1307, USA. */ ++ ++#include <pthread.h> ++#include <pt-internal.h> ++ ++error_t ++__pthread_init_specific (struct __pthread *thread) ++{ ++ thread->thread_specifics = 0; ++ thread->have_kernel_resources = 0; ++ return 0; ++} diff --git a/debian/patches/libpthread_globsigdisp.patch b/debian/patches/libpthread_globsigdisp.patch new file mode 100644 index 00000000..06c3486c --- /dev/null +++ b/debian/patches/libpthread_globsigdisp.patch @@ -0,0 +1,59 @@ +commit 60d1b9b9198bc8c618596cb0e48687bd41e8adb7 +Author: Jeremie Koenig <jk@jk.fr.eu.org> +Date: Fri Jun 10 05:46:39 2011 +0000 + + Mark new threads as global signal receivers + + * sysdeps/mach/hurd/pt-sigstate-init.c (__pthread_sigstate_init): + Call _hurd_sigstate_set_global_rcv for newly created threads. + * sysdeps/mach/pt-thread-halt.c (__pthread_thread_halt): + Call _hurd_sigstate_delete on terminated threads. + +diff --git a/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c b/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c +index da5a945..f8398f4 100644 +--- a/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c ++++ b/libpthread/sysdeps/mach/hurd/pt-sigstate-init.c +@@ -19,6 +19,7 @@ + + #include <pthread.h> + #include <hurd/threadvar.h> ++#include <hurd/signal.h> + + #include <pt-internal.h> + +@@ -30,8 +31,21 @@ __pthread_sigstate_init (struct __pthread *thread) + thread->stackaddr); + + /* The real initialization happens internally in glibc the first +- time that _hurd_thead_sigstate is called. */ ++ time that _hurd_self_sigstate is called. */ + *location = 0; + ++ /* Mark the thread as a global signal receiver so as to conform with ++ the pthread semantics. However, we must be careful. The first ++ pthread created is the main thread, during libpthread initialization. ++ We must not mark it, otherwise the sigprocmask call in ++ __pthread_create would try to access _hurd_global_sigstate, ++ which is not initialized yet. When glibc runs _hurdsig_init later ++ on, the message thread is created, which must not be marked either. */ ++ if (__pthread_num_threads > 2) ++ { ++ struct hurd_sigstate *ss = _hurd_thread_sigstate (thread->kernel_thread); ++ _hurd_sigstate_set_global_rcv (ss); ++ } ++ + return 0; + } +diff --git a/libpthread/sysdeps/mach/pt-thread-halt.c b/libpthread/sysdeps/mach/pt-thread-halt.c +index a9c3858..808043d 100644 +--- a/libpthread/sysdeps/mach/pt-thread-halt.c ++++ b/libpthread/sysdeps/mach/pt-thread-halt.c +@@ -34,6 +34,8 @@ __pthread_thread_halt (struct __pthread *thread) + { + if (thread->have_kernel_resources) + { ++ _hurd_sigstate_delete (thread->kernel_thread); ++ + if (thread == _pthread_self ()) + { + while (1) diff --git a/debian/patches/libpthread_procfs.patch b/debian/patches/libpthread_procfs.patch new file mode 100644 index 00000000..2ad9e2e8 --- /dev/null +++ b/debian/patches/libpthread_procfs.patch @@ -0,0 +1,83 @@ +Include libpthread and procfs in the build + +Index: hurd-debian/Makefile +=================================================================== +--- hurd-debian.orig/Makefile 2010-09-27 19:42:53.000000000 +0000 ++++ hurd-debian/Makefile 2010-09-27 19:45:57.000000000 +0000 +@@ -31,7 +31,8 @@ + # Hurd libraries + lib-subdirs = libshouldbeinlibc libihash libiohelp libports libthreads \ + libpager libfshelp libdiskfs libtrivfs libps \ +- libnetfs libpipe libstore libhurdbugaddr libftpconn libcons ++ libnetfs libpipe libstore libhurdbugaddr libftpconn libcons \ ++ libpthread + + # Hurd programs + prog-subdirs = auth proc exec init term \ +@@ -40,7 +41,7 @@ + login daemons nfsd boot console \ + hostmux usermux ftpfs trans \ + console-client utils sutils ufs-fsck ufs-utils \ +- benchmarks fstests ++ benchmarks fstests procfs random + + # Other directories + other-subdirs = hurd doc config release include +Index: hurd-debian/procfs/Makefile +=================================================================== +--- hurd-debian.orig/procfs/Makefile 2010-09-27 19:50:41.000000000 +0000 ++++ hurd-debian/procfs/Makefile 2010-09-27 19:50:46.000000000 +0000 +@@ -1,26 +1,30 @@ +-TARGET = procfs +-OBJS = procfs.o netfs.o procfs_dir.o \ +- process.o proclist.o rootdir.o dircat.o main.o +-LIBS = -lnetfs -lps ++# Makefile - for procfs ++# ++# Copyright (C) 2008 Free Software Foundation, Inc. ++# ++# This program is free software; you can redistribute it and/or ++# modify it under the terms of the GNU General Public License as ++# published by the Free Software Foundation; either version 2, or (at ++# your option) any later version. ++# ++# This program is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++# General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program; if not, write to the Free Software ++# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ ++dir := procfs ++makemode := server ++ ++target = procfs + +-CC = gcc +-CFLAGS = -Wall -g +-CPPFLAGS = +-LDFLAGS = ++SRCS = procfs.c netfs.c procfs_dir.c process.c proclist.c rootdir.c dircat.c main.c ++LCLHDRS = dircat.h main.h process.h procfs.h procfs_dir.h proclist.h rootdir.h + +-ifdef PROFILE +-CFLAGS= -g -pg +-CPPFLAGS= -DPROFILE +-LDFLAGS= -static +-LIBS= -lnetfs -lfshelp -liohelp -lps -lports -lthreads -lihash -lshouldbeinlibc +-endif ++OBJS = $(SRCS:.c=.o) ++HURDLIBS = netfs fshelp iohelp ps ports threads ihash shouldbeinlibc + +-CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 +- +-all: $(TARGET) +- +-$(TARGET): $(OBJS) +- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) +- +-clean: +- $(RM) $(TARGET) $(OBJS) ++include ../Makeconf diff --git a/debian/patches/libpthread_sigmask.patch b/debian/patches/libpthread_sigmask.patch new file mode 100644 index 00000000..7315a80d --- /dev/null +++ b/debian/patches/libpthread_sigmask.patch @@ -0,0 +1,47 @@ +* libpthread/sysdeps/mach/hurd/pt-sigstate.c (__pthread_sigstate): Wake up the message +thread if any pending signals have been unblocked (code grabbed from glibc). +--- + libpthread/sysdeps/mach/hurd/pt-sigstate.c | 9 +++++++++ + 1 files changed, 9 insertions(+), 0 deletions(-) + +Index: hurd/libpthread/sysdeps/mach/hurd/pt-sigstate.c +=================================================================== +--- hurd.orig/libpthread/sysdeps/mach/hurd/pt-sigstate.c 2011-05-29 15:23:30.000000000 +0000 ++++ hurd/libpthread/sysdeps/mach/hurd/pt-sigstate.c 2011-06-10 04:53:53.000000000 +0000 +@@ -21,6 +21,7 @@ + #include <assert.h> + #include <signal.h> + #include <hurd/signal.h> ++#include <hurd/msg.h> + + #include <pt-internal.h> + +@@ -31,11 +32,12 @@ + { + error_t err = 0; + struct hurd_sigstate *ss; ++ sigset_t pending; + + ss = _hurd_thread_sigstate (thread->kernel_thread); + assert (ss); + +- __pthread_spin_lock (&ss->lock); ++ _hurd_sigstate_lock (ss); + + if (oset) + *oset = ss->blocked; +@@ -63,7 +65,13 @@ + if (! err && clear_pending) + __sigemptyset (&ss->pending); + +- __pthread_spin_unlock (&ss->lock); ++ pending = _hurd_sigstate_pending (ss) & ~ss->blocked; ++ _hurd_sigstate_unlock (ss); ++ ++ if (! err && pending) ++ /* Send a message to the signal thread so it ++ will wake up and check for pending signals. */ ++ __msg_sig_post (_hurd_msgport, 0, 0, __mach_task_self ()); + + return err; + } diff --git a/debian/patches/libpthread_stubs.patch b/debian/patches/libpthread_stubs.patch new file mode 100644 index 00000000..7b0db6a3 --- /dev/null +++ b/debian/patches/libpthread_stubs.patch @@ -0,0 +1,157 @@ +Add warnings about non-implemented functions. +--- + config.make.in | 1 + + libpthread/Makefile | 14 +++++++++++++- + libpthread/include/libc-symbols.h | 1 + + libpthread/sysdeps/generic/pt-atfork.c | 2 ++ + libpthread/sysdeps/generic/pt-getcpuclockid.c | 1 + + libpthread/sysdeps/generic/pt-getschedparam.c | 2 ++ + libpthread/sysdeps/generic/pt-key-create.c | 2 ++ + libpthread/sysdeps/generic/pt-key-delete.c | 2 ++ + libpthread/sysdeps/generic/pt-mutex-getprioceiling.c | 2 ++ + libpthread/sysdeps/generic/pt-mutex-setprioceiling.c | 2 ++ + libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c | 2 ++ + libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c | 2 ++ + libpthread/sysdeps/generic/pt-setschedparam.c | 2 ++ + libpthread/sysdeps/generic/pt-setschedprio.c | 2 ++ + 14 files changed, 36 insertions(+), 1 deletion(-) + +--- a/config.make.in ++++ b/config.make.in +@@ -44,6 +44,7 @@ RANLIB = @RANLIB@ + MIG = @MIG@ + MIGCOM = $(MIG) -cc cat - /dev/null + AWK = @AWK@ ++OBJDUMP = objdump + + # Compilation flags. Append these to the definitions already made by + # the specific Makefile. +--- a/libpthread/Makefile ++++ b/libpthread/Makefile +@@ -186,7 +186,7 @@ CPPFLAGS += \ + -imacros $(srcdir)/not-in-libc.h + + +-install: install-headers $(libdir)/libpthread2.a $(libdir)/libpthread2_pic.a ++install: install-headers $(libdir)/libpthread2.a $(libdir)/libpthread2_pic.a install-stubs-pthread + install-headers: $(addprefix $(includedir)/, $(sysdeps_headers)) + + # XXX: If $(libdir)/libpthread2.a is installed and +@@ -205,6 +205,18 @@ $(libdir)/libpthread2_pic.a: $(libdir)/l + mv $< $@ + $(INSTALL_DATA) $(srcdir)/libpthread_pic.a $< + ++install-stubs-pthread: stubs-pthread.h ++ mkdir -p $(includedir)/gnu ++ $(INSTALL_DATA) $< $(includedir)/gnu/stubs-pthread.h ++ ++stubs-pthread.h: $(OBJS) ++ $(OBJDUMP) -h $^ | \ ++ $(AWK) '/\.gnu\.glibc-stub\./ { \ ++ sub(/\.gnu\.glibc-stub\./, "", $$2); \ ++ stubs[$$2] = 1; } \ ++ END { for (s in stubs) print "#define __stub_" s }' > $@T ++ mv -f $@T $@ ++ + .PHONY: $(addprefix $(includedir)/, $(sysdeps_headers)) + + $(addprefix $(includedir)/, $(sysdeps_headers)): +--- a/libpthread/include/libc-symbols.h ++++ b/libpthread/include/libc-symbols.h +@@ -252,6 +252,7 @@ + + /* A canned warning for sysdeps/stub functions. */ + #define stub_warning(name) \ ++ __make_section_unallocated (".gnu.glibc-stub." #name) \ + link_warning (name, \ + "warning: " #name " is not implemented and will always fail") + +--- a/libpthread/sysdeps/generic/pt-atfork.c ++++ b/libpthread/sysdeps/generic/pt-atfork.c +@@ -27,3 +27,5 @@ pthread_atfork (void (*prepare) (void), + { + return ENOSYS; + } ++ ++stub_warning (pthread_atfork) +--- a/libpthread/sysdeps/generic/pt-getcpuclockid.c ++++ b/libpthread/sysdeps/generic/pt-getcpuclockid.c +@@ -30,5 +30,6 @@ pthread_getcpuclockid (pthread_t thread, + return 0; + #else + return ENOSYS; ++stub_warning (pthread_getcpuclockid) + #endif + } +--- a/libpthread/sysdeps/generic/pt-getschedparam.c ++++ b/libpthread/sysdeps/generic/pt-getschedparam.c +@@ -26,3 +26,5 @@ pthread_getschedparam (pthread_t thread, + { + return ENOSYS; + } ++ ++stub_warning (pthread_getschedparam) +--- a/libpthread/sysdeps/generic/pt-key-create.c ++++ b/libpthread/sysdeps/generic/pt-key-create.c +@@ -25,3 +25,5 @@ pthread_key_create (pthread_key_t *key, + { + return ENOSYS; + } ++ ++stub_warning (pthread_key_create) +--- a/libpthread/sysdeps/generic/pt-key-delete.c ++++ b/libpthread/sysdeps/generic/pt-key-delete.c +@@ -25,3 +25,5 @@ pthread_key_delete (pthread_key_t key) + { + return ENOSYS; + } ++ ++stub_warning (pthread_key_delete) +--- a/libpthread/sysdeps/generic/pt-mutex-getprioceiling.c ++++ b/libpthread/sysdeps/generic/pt-mutex-getprioceiling.c +@@ -26,3 +26,5 @@ pthread_mutex_getprioceiling (const pthr + { + return ENOSYS; + } ++ ++stub_warning (pthread_mutex_getprioceiling) +--- a/libpthread/sysdeps/generic/pt-mutex-setprioceiling.c ++++ b/libpthread/sysdeps/generic/pt-mutex-setprioceiling.c +@@ -26,3 +26,5 @@ pthread_mutex_setprioceiling (pthread_mu + { + return ENOSYS; + } ++ ++stub_warning (pthread_mutex_setprioceiling) +--- a/libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c ++++ b/libpthread/sysdeps/generic/pt-mutexattr-getprioceiling.c +@@ -26,3 +26,5 @@ pthread_mutexattr_getprioceiling (const + { + return ENOSYS; + } ++ ++stub_warning (pthread_mutexattr_getprioceiling) +--- a/libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c ++++ b/libpthread/sysdeps/generic/pt-mutexattr-setprioceiling.c +@@ -26,3 +26,5 @@ pthread_mutexattr_setprioceiling (pthrea + { + return ENOSYS; + } ++ ++stub_warning (pthread_mutexattr_setprioceiling) +--- a/libpthread/sysdeps/generic/pt-setschedparam.c ++++ b/libpthread/sysdeps/generic/pt-setschedparam.c +@@ -26,3 +26,5 @@ pthread_setschedparam (pthread_t thread, + { + return ENOSYS; + } ++ ++stub_warning (pthread_setschedparam) +--- a/libpthread/sysdeps/generic/pt-setschedprio.c ++++ b/libpthread/sysdeps/generic/pt-setschedprio.c +@@ -25,3 +25,5 @@ pthread_setschedprio (pthread_t thread, + { + return ENOSYS; + } ++ ++stub_warning (pthread_setschedprio) diff --git a/debian/patches/libpthread_tls.patch b/debian/patches/libpthread_tls.patch new file mode 100644 index 00000000..245ef081 --- /dev/null +++ b/debian/patches/libpthread_tls.patch @@ -0,0 +1,331 @@ +Add TLS support +TODO: drop threadvar support +--- + libpthread/pthread/pt-create.c | 7 ++++ + libpthread/pthread/pt-exit.c | 3 ++ + libpthread/pthread/pt-internal.h | 19 ++++++++++++ + libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c | 37 ++++++++++++++++++++++--- + libpthread/sysdeps/mach/hurd/ia32/pt-setup.c | 7 +++- + libpthread/sysdeps/mach/hurd/pt-docancel.c | 4 +- + libpthread/sysdeps/mach/hurd/pt-sysdep.h | 10 ++++-- + libthreads/alpha/thread.c | 1 + libthreads/cprocs.c | 3 +- + libthreads/cthread_internals.h | 16 ++++++++++ + libthreads/i386/thread.c | 32 +++++++++++++++++++-- + 11 files changed, 122 insertions(+), 17 deletions(-) + +--- a/libpthread/pthread/pt-create.c ++++ b/libpthread/pthread/pt-create.c +@@ -129,6 +129,11 @@ __pthread_create_internal (struct __pthr + if (err) + goto failed_thread_alloc; + ++ pthread->tcb = _dl_allocate_tls (NULL); ++ if (!pthread->tcb) ++ goto failed_thread_tls_alloc; ++ pthread->tcb->tcb = pthread->tcb; ++ + /* And initialize the rest of the machine context. This may include + additional machine- and system-specific initializations that + prove convenient. */ +@@ -194,6 +199,8 @@ __pthread_create_internal (struct __pthr + failed_sigstate: + __pthread_sigstate_destroy (pthread); + failed_setup: ++ _dl_deallocate_tls (pthread->tcb, 1); ++ failed_thread_tls_alloc: + __pthread_thread_dealloc (pthread); + __pthread_thread_halt (pthread); + failed_thread_alloc: +--- a/libpthread/pthread/pt-exit.c ++++ b/libpthread/pthread/pt-exit.c +@@ -70,6 +70,9 @@ pthread_exit (void *status) + if (self->cancel_state == PTHREAD_CANCEL_ENABLE && self->cancel_pending) + status = PTHREAD_CANCELED; + ++ if (self->tcb) ++ _dl_deallocate_tls (self->tcb, 1); ++ + switch (self->state) + { + default: +--- a/libpthread/pthread/pt-internal.h ++++ b/libpthread/pthread/pt-internal.h +@@ -54,6 +54,14 @@ enum pthread_state + # define PTHREAD_SYSDEP_MEMBERS + #endif + ++/* Type of the TCB. */ ++typedef struct ++{ ++ void *tcb; /* Points to this structure. */ ++ void *dtv; /* Vector of pointers to TLS data. */ ++ thread_t self; /* This thread's control port. */ ++} tcbhead_t; ++ + /* This structure describes a POSIX thread. */ + struct __pthread + { +@@ -89,6 +97,8 @@ struct __pthread + + PTHREAD_SYSDEP_MEMBERS + ++ tcbhead_t *tcb; ++ + struct __pthread *next, **prevp; + }; + +@@ -287,4 +297,13 @@ const struct __pthread_rwlockattr __pthr + /* Default condition attributes. */ + const struct __pthread_condattr __pthread_default_condattr; + ++ ++/* From glibc. */ ++ ++/* Dynamic linker TLS allocation. */ ++extern void *_dl_allocate_tls(void *); ++ ++/* Dynamic linker TLS deallocation. */ ++extern void _dl_deallocate_tls(void *, int); ++ + #endif /* pt-internal.h */ +--- a/libpthread/sysdeps/mach/hurd/pt-docancel.c ++++ b/libpthread/sysdeps/mach/hurd/pt-docancel.c +@@ -52,8 +52,8 @@ __pthread_do_cancel (struct __pthread *p + err = __thread_abort (p->kernel_thread); + assert_perror (err); + +- err = __thread_set_pcsp (p->kernel_thread, +- 1, (void *) call_exit, 0, 0); ++ err = __thread_set_pcsptp (p->kernel_thread, ++ 1, (void *) call_exit, 0, 0, 0, 0); + assert_perror (err); + + err = __thread_resume (p->kernel_thread); +--- a/libpthread/sysdeps/mach/hurd/pt-sysdep.h ++++ b/libpthread/sysdeps/mach/hurd/pt-sysdep.h +@@ -60,11 +60,13 @@ __pthread_stack_dealloc (void *stackaddr + __vm_deallocate (__mach_task_self (), (vm_offset_t) stackaddr, stacksize); + } + +-/* Change thread THREAD's program counter to PC if SET_PC is true and +- its stack pointer to SP if SET_IP is true. */ +-extern int __thread_set_pcsp (thread_t thread, ++/* Change thread THREAD's program counter to PC if SET_PC is true, ++ its stack pointer to SP if SET_IP is true, and its thread pointer ++ to TP if SET_TP is true. */ ++extern int __thread_set_pcsptp (thread_t thread, + int set_pc, void *pc, +- int set_sp, void *sp); ++ int set_sp, void *sp, ++ int set_tp, void *tp); + + + #endif /* pt-sysdep.h */ +--- a/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c ++++ b/libpthread/sysdeps/mach/hurd/ia32/pt-machdep.c +@@ -21,12 +21,28 @@ + + #include <mach.h> + #include <mach/i386/thread_status.h> ++#include <mach/i386/mach_i386.h> ++#include <mach/mig_errors.h> + #include <mach/thread_status.h> + ++#define HURD_TLS_DESC_DECL(desc, tcb) \ ++ struct descriptor desc = \ ++ { /* low word: */ \ ++ 0xffff /* limit 0..15 */ \ ++ | (((unsigned int) (tcb)) << 16) /* base 0..15 */ \ ++ , /* high word: */ \ ++ ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \ ++ | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \ ++ | (0xf << 16) /* limit 16..19 */ \ ++ | ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \ ++ | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \ ++ } ++ + int +-__thread_set_pcsp (thread_t thread, ++__thread_set_pcsptp (thread_t thread, + int set_ip, void *ip, +- int set_sp, void *sp) ++ int set_sp, void *sp, ++ int set_tp, void *tp) + { + error_t err; + struct i386_thread_state state; +@@ -34,7 +50,7 @@ __thread_set_pcsp (thread_t thread, + + state_count = i386_THREAD_STATE_COUNT; + +- err = __thread_get_state (thread, i386_THREAD_STATE, ++ err = __thread_get_state (thread, i386_REGS_SEGS_STATE, + (thread_state_t) &state, &state_count); + if (err) + return err; +@@ -43,8 +59,21 @@ __thread_set_pcsp (thread_t thread, + state.uesp = (unsigned int) sp; + if (set_ip) + state.eip = (unsigned int) ip; ++ if (set_tp) { ++ HURD_TLS_DESC_DECL(desc, tp); ++ int sel; ++ ++ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0)); ++ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ ++ err = __i386_set_ldt (thread, sel, &desc, 1); ++ else ++ err = __i386_set_gdt (thread, &sel, desc); ++ if (err) ++ return err; ++ state.gs = sel; ++ } + +- err = __thread_set_state (thread, i386_THREAD_STATE, ++ err = __thread_set_state (thread, i386_REGS_SEGS_STATE, + (thread_state_t) &state, + i386_THREAD_STATE_COUNT); + if (err) +--- a/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c ++++ b/libpthread/sysdeps/mach/hurd/ia32/pt-setup.c +@@ -91,12 +91,15 @@ __pthread_setup (struct __pthread *threa + thread->mcontext.pc = entry_point; + thread->mcontext.sp = stack_setup (thread, start_routine, arg); + ++ thread->tcb->self = thread->kernel_thread; ++ + ktid = __mach_thread_self (); + if (thread->kernel_thread != ktid) + { +- err = __thread_set_pcsp (thread->kernel_thread, ++ err = __thread_set_pcsptp (thread->kernel_thread, + 1, thread->mcontext.pc, +- 1, thread->mcontext.sp); ++ 1, thread->mcontext.sp, ++ 1, thread->tcb); + assert_perror (err); + } + __mach_port_deallocate (__mach_task_self (), ktid); +--- a/libthreads/cprocs.c ++++ b/libthreads/cprocs.c +@@ -730,10 +730,11 @@ cproc_create(void) + spin_lock(&n_kern_lock); + if (cthread_max_kernel_threads == 0 || + cthread_kernel_threads < cthread_max_kernel_threads) { ++ tcbhead_t *tcb = _dl_allocate_tls(NULL); + cthread_kernel_threads++; + spin_unlock(&n_kern_lock); + MACH_CALL(thread_create(mach_task_self(), &n), r); +- cproc_setup(child, n, cthread_body); /* machine dependent */ ++ cproc_setup(child, n, tcb, cthread_body); /* machine dependent */ + MACH_CALL(thread_resume(n), r); + #ifdef STATISTICS + spin_lock(&ready_lock); +--- a/libthreads/cthread_internals.h ++++ b/libthreads/cthread_internals.h +@@ -166,6 +166,14 @@ + # endif + #endif + ++/* Type of the TCB. */ ++typedef struct ++{ ++ void *tcb; /* Points to this structure. */ ++ void *dtv; /* Vector of pointers to TLS data. */ ++ thread_t self; /* This thread's control port. */ ++} tcbhead_t; ++ + /* + * Low-level thread implementation. + * This structure must agree with struct ur_cthread in cthreads.h +@@ -312,4 +320,10 @@ extern void cproc_prepare(cproc_t _chil + void (*cthread_body_pc)()); + + extern void cproc_setup(cproc_t _child, thread_t _mach_thread, +- void (*_routine)(cproc_t)); ++ tcbhead_t *tcb, void (*_routine)(cproc_t)); ++ ++ ++/* From glibc. */ ++ ++/* Dynamic linker TLS allocation. */ ++extern void *_dl_allocate_tls(void *); +--- a/libthreads/alpha/thread.c ++++ b/libthreads/alpha/thread.c +@@ -74,6 +74,7 @@ void + cproc_setup( + register cproc_t child, + thread_t thread, ++ tcbhead_t *tcb, /* TODO */ + void (*routine)(cproc_t)) + { + register integer_t *top; +--- a/libthreads/i386/thread.c ++++ b/libthreads/i386/thread.c +@@ -75,6 +75,21 @@ char rcs_id[] = "$Header: /cvsroot/hurd/ + #include <cthreads.h> + #include "cthread_internals.h" + #include <mach.h> ++#include <mach/i386/mach_i386.h> ++#include <mach/mig_errors.h> ++ ++#define HURD_TLS_DESC_DECL(desc, tcb) \ ++ struct descriptor desc = \ ++ { /* low word: */ \ ++ 0xffff /* limit 0..15 */ \ ++ | (((unsigned int) (tcb)) << 16) /* base 0..15 */ \ ++ , /* high word: */ \ ++ ((((unsigned int) (tcb)) >> 16) & 0xff) /* base 16..23 */ \ ++ | ((0x12 | 0x60 | 0x80) << 8) /* access = ACC_DATA_W|ACC_PL_U|ACC_P */ \ ++ | (0xf << 16) /* limit 16..19 */ \ ++ | ((4 | 8) << 20) /* granularity = SZ_32|SZ_G */ \ ++ | (((unsigned int) (tcb)) & 0xff000000) /* base 24..31 */ \ ++ } + + /* + * Set up the initial state of a MACH thread +@@ -82,7 +97,7 @@ char rcs_id[] = "$Header: /cvsroot/hurd/ + * when it is resumed. + */ + void +-cproc_setup(register cproc_t child, thread_t thread, void (*routine)(cproc_t)) ++cproc_setup(register cproc_t child, thread_t thread, tcbhead_t *tcb, void (*routine)(cproc_t)) + { + extern unsigned int __hurd_threadvar_max; /* GNU */ + register int *top = (int *) +@@ -95,13 +110,15 @@ cproc_setup(register cproc_t child, thre + register struct i386_thread_state *ts = &state; + kern_return_t r; + unsigned int count; ++ HURD_TLS_DESC_DECL(desc, tcb); ++ int sel; + + /* + * Set up i386 call frame and registers. + * Read registers first to get correct segment values. + */ + count = i386_THREAD_STATE_COUNT; +- MACH_CALL(thread_get_state(thread,i386_THREAD_STATE,(thread_state_t) &state,&count),r); ++ MACH_CALL(thread_get_state(thread,i386_REGS_SEGS_STATE,(thread_state_t) &state,&count),r); + + ts->eip = (int) routine; + *--top = (int) child; /* argument to function */ +@@ -109,7 +126,16 @@ cproc_setup(register cproc_t child, thre + ts->uesp = (int) top; /* set stack pointer */ + ts->ebp = 0; /* clear frame pointer */ + +- MACH_CALL(thread_set_state(thread,i386_THREAD_STATE,(thread_state_t) &state,i386_THREAD_STATE_COUNT),r); ++ asm ("mov %%gs, %w0" : "=q" (sel) : "0" (0)); ++ tcb->tcb = tcb; ++ tcb->self = thread; ++ if (__builtin_expect (sel, 0x48) & 4) /* LDT selector */ ++ __i386_set_ldt (thread, sel, &desc, 1); ++ else ++ __i386_set_gdt (thread, &sel, desc); ++ ts->gs = sel; ++ ++ MACH_CALL(thread_set_state(thread,i386_REGS_SEGS_STATE,(thread_state_t) &state,i386_THREAD_STATE_COUNT),r); + } + + #if defined(cthread_sp) diff --git a/debian/patches/makedev.diff b/debian/patches/makedev.diff new file mode 100644 index 00000000..f53320c5 --- /dev/null +++ b/debian/patches/makedev.diff @@ -0,0 +1,17 @@ +Do not create the shm node since Marcus' SHM implementation uses a directory +there. +--- + sutils/MAKEDEV.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/sutils/MAKEDEV.sh ++++ b/sutils/MAKEDEV.sh +@@ -86,7 +86,7 @@ function mkdev { + ;; + + std) +- mkdev console tty null zero full fd time mem klog shm ++ mkdev console tty null zero full fd time mem klog + ;; + console|com[0-9]) + st $I root 600 /hurd/term ${DEVDIR}/$I device $I;; diff --git a/debian/patches/makedev_keep_options.patch b/debian/patches/makedev_keep_options.patch new file mode 100644 index 00000000..69a57e48 --- /dev/null +++ b/debian/patches/makedev_keep_options.patch @@ -0,0 +1,58 @@ +Add options -k and -K to MAKEDEV.sh to chose not to overwrite existing entries. + +TODO: submit to bug-hurd + +Index: hurd/sutils/MAKEDEV.sh +=================================================================== +--- hurd.orig/sutils/MAKEDEV.sh 2010-07-01 18:14:22.000000000 +0200 ++++ hurd/sutils/MAKEDEV.sh 2010-07-01 18:17:37.000000000 +0200 +@@ -8,6 +8,8 @@ + ECHO=: # Change to "echo" to echo commands. + EXEC="" # Change to ":" to suppress command execution. + DEVDIR=`pwd` # Reset below by -D/--devdir command line option. ++STFLAGS="-g" # Set to -k if active translators are to be kept. ++KEEP= # Set to something if existing files are to be left alone. + + while :; do + case "$1" in +@@ -18,6 +20,8 @@ + + -D, --devdir=DIR Use DIR when a device node name must be + embedded in a translator; default is the cwd ++ -k, --keep-active Leave any existing active translator running ++ -K, --keep-all Don't overwrite existing files + -n, --dry-run Don't actually execute any commands + -v, --verbose Show what commands are executed to make the devices + -?, --help Give this help list +@@ -28,11 +32,14 @@ + --devdir=*) DEVDIR="`echo "$1" | sed 's/^--devdir=//'`"; shift 1;; + -D) DEVDIR="$2"; shift 2;; + -D*) DEVDIR="`echo "$1" | sed 's/^-D//'`"; shift 1;; ++ --keep-active|-k) STFLAGS="-k"; shift;; ++ --keep-all|-K) KEEP=1; shift;; + --verbose|-v) ECHO=echo; shift;; + --dry-run|-n) EXEC=:; shift;; + -nv|-vn) ECHO=echo; EXEC=:; shift;; + --usage) +- echo "Usage: $0 [-V?] [-D DIR] [--help] [--usage] [--version] [--devdir=DIR] DEVNAME..." ++ echo "Usage: $0 [-V?] [-D DIR] [--help] [--usage] [--version]" ++ echo " [--devdir=DIR] [--keep-active] [--keep-all] DEVNAME..." + exit 0;; + --version|-V) + echo "STANDARD_HURD_VERSION_MAKEDEV_"; exit 0;; +@@ -61,10 +68,13 @@ + local OWNER="$2" + local PERM="$3" + shift 3 +- if cmd settrans -cg "$NODE"; then ++ if [ "$KEEP" ] && showtrans "$NODE" > /dev/null 2>&1 ; then ++ return; ++ fi ++ if cmd settrans $STFLAGS -c "$NODE"; then + cmd chown "$OWNER" "$NODE" + cmd chmod "$PERM" "$NODE" +- cmd settrans "$NODE" "$@" ++ cmd settrans $STFLAGS "$NODE" "$@" + fi + } + diff --git a/debian/patches/makedev_parted_store.patch b/debian/patches/makedev_parted_store.patch new file mode 100644 index 00000000..7d3d8be5 --- /dev/null +++ b/debian/patches/makedev_parted_store.patch @@ -0,0 +1,72 @@ +Add option -p to MAKEDEV to use user-space parted stores for partition devices. + +TODO: use in installed system, test, and submit to bug-hurd + +Index: hurd/sutils/MAKEDEV.sh +=================================================================== +--- hurd.orig/sutils/MAKEDEV.sh 2010-07-08 00:48:13.000000000 +0000 ++++ hurd/sutils/MAKEDEV.sh 2010-07-08 01:18:26.000000000 +0000 +@@ -10,6 +10,7 @@ + DEVDIR=`pwd` # Reset below by -D/--devdir command line option. + STFLAGS="-g" # Set to -k if active translators are to be kept. + KEEP= # Set to something if existing files are to be left alone. ++USE_PARTSTORE= # Whether to use the newer part: stores + + while :; do + case "$1" in +@@ -22,6 +23,8 @@ + embedded in a translator; default is the cwd + -k, --keep-active Leave any existing active translator running + -K, --keep-all Don't overwrite existing files ++ -p, --parted Prefer user-space parted stores to kernel devices ++ for partition devices + -n, --dry-run Don't actually execute any commands + -v, --verbose Show what commands are executed to make the devices + -?, --help Give this help list +@@ -34,11 +37,12 @@ + -D*) DEVDIR="`echo "$1" | sed 's/^-D//'`"; shift 1;; + --keep-active|-k) STFLAGS="-k"; shift;; + --keep-all|-K) KEEP=1; shift;; ++ --parted|-p) USE_PARTSTORE=1; shift;; + --verbose|-v) ECHO=echo; shift;; + --dry-run|-n) EXEC=:; shift;; + -nv|-vn) ECHO=echo; EXEC=:; shift;; + --usage) +- echo "Usage: $0 [-V?] [-D DIR] [--help] [--usage] [--version]" ++ echo "Usage: $0 [-V?] [-D DIR] [--help] [--usage] [--version] [--parted]" + echo " [--devdir=DIR] [--keep-active] [--keep-all] DEVNAME..." + exit 0;; + --version|-V) +@@ -150,6 +154,7 @@ + ;; + + [hrsc]d*) ++ local sliceno= + local n="${I#?d}" + local major="${n%%[!0-9]*}" + if [ -z "$major" ]; then +@@ -170,7 +175,9 @@ + ;; + esac + case "$rest" in +- '') ;; # Whole slice ++ '') # Whole slice, can use parted stores ++ sliceno=$slice ++ ;; + [a-z]) ;; # BSD partition after slice + *) + lose "$I: Invalid partition \`$rest'" +@@ -183,7 +190,12 @@ + esac + + # The device name passed all syntax checks, so finally use it! +- st $I root 640 /hurd/storeio $I ++ if [ "$USE_PARTSTORE" ] && [ -z "$rest" ] && [ "$sliceno" ]; then ++ local dev=${I%s[0-9]*} ++ st $I root 640 /hurd/storeio -T typed part:$sliceno:device:$dev ++ else ++ st $I root 640 /hurd/storeio $I ++ fi + ;; + + # /dev/shm is used by the POSIX.1 shm_open call in libc. diff --git a/debian/patches/pfinet_dhcp.patch b/debian/patches/pfinet_dhcp.patch new file mode 100644 index 00000000..30c0902a --- /dev/null +++ b/debian/patches/pfinet_dhcp.patch @@ -0,0 +1,560 @@ +2007-10-14 Christian Dietrich <stettberger@dokucode.de> + + * options.c (options): Marked -a, -g -m, -p, -A, -G + OPTION_ARG_OPTIONAL. Adding -d option. + (parse_interface_copy_device): New function. + (parse_opt): When selecting another interface with -i + set the options from e.g. a prior fsysopts call as default + values. For -a, -g, -p, -g, -A, -G set the optional + argument as value. When there is no argument, delete the + value (e.g. unset default gateway). Delete delete default gateways + only if the set gateway is on an interface modified in this call. + Add always an route for dhcp packages on all devices. By doing + this we can send dhcp renew packages. + (trivfs_append_args): Add --gateway only once. + +2007-10-14 Marco Gerards <metgerards@student.han.nl> + + * options.c (options): Add the option `dhcp'. + (parse_hook_add_interface): Initialize the `dhcp' member for the + parse hook. + (parse_opt): In case pfinet is started with the argument `--dhcp', + set the address to `0.0.0.0', the netmask to `255.0.0.0' and add + the route for `0.0.0.0' so broadcasting works. + + * linux-src/net/ipv4/devinet.c (inet_insert_ifa) [_HURD_]: Don't + fail when the address is `0.0.0.0'. + +--- + pfinet/linux-src/net/ipv4/devinet.c | 2 + pfinet/options.c | 381 ++++++++++++++++++++++++++---------- + 2 files changed, 278 insertions(+), 105 deletions(-) + +--- a/pfinet/options.c ++++ b/pfinet/options.c +@@ -60,23 +60,26 @@ extern struct inet6_dev *ipv6_find_idev + extern int inet6_addr_add (int ifindex, struct in6_addr *pfx, int plen); + extern int inet6_addr_del (int ifindex, struct in6_addr *pfx, int plen); + ++#ifdef CONFIG_IPV6 ++static struct rt6_info * ipv6_get_dflt_router (void); ++#endif ++ + + /* Pfinet options. Used for both startup and runtime. */ + static const struct argp_option options[] = + { +- {"interface", 'i', "DEVICE", 0, "Network interface to use", 1}, ++ {"interface", 'i', "DEVICE", 0, "Network interface to use", 1}, + {0,0,0,0,"These apply to a given interface:", 2}, +- {"address", 'a', "ADDRESS", 0, "Set the network address"}, +- {"netmask", 'm', "MASK", 0, "Set the netmask"}, +- {"peer", 'p', "ADDRESS", 0, "Set the peer address"}, +- {"gateway", 'g', "ADDRESS", 0, "Set the default gateway"}, +- {"ipv4", '4', "NAME", 0, "Put active IPv4 translator on NAME"}, ++ {"address", 'a', "ADDRESS", OPTION_ARG_OPTIONAL, "Set the network address"}, ++ {"netmask", 'm', "MASK", OPTION_ARG_OPTIONAL, "Set the netmask"}, ++ {"peer", 'p', "ADDRESS", OPTION_ARG_OPTIONAL, "Set the peer address"}, ++ {"gateway", 'g', "ADDRESS", OPTION_ARG_OPTIONAL, "Set the default gateway"}, ++ {"ipv4", '4', "NAME", 0, "Put active IPv4 translator on NAME"}, + #ifdef CONFIG_IPV6 +- {"ipv6", '6', "NAME", 0, "Put active IPv6 translator on NAME"}, +- {"address6", 'A', "ADDR/LEN",0, "Set the global IPv6 address"}, +- {"gateway6", 'G', "ADDRESS", 0, "Set the IPv6 default gateway"}, ++ {"ipv6", '6', "NAME", 0, "Put active IPv6 translator on NAME"}, ++ {"address6", 'A', "ADDR/LEN", OPTION_ARG_OPTIONAL, "Set the global IPv6 address"}, ++ {"gateway6", 'G', "ADDRESS", OPTION_ARG_OPTIONAL, "Set the IPv6 default gateway"}, + #endif +- {"shutdown", 's', 0, 0, "Shut it down"}, + {0} + }; + +@@ -112,6 +115,50 @@ struct parse_hook + struct parse_interface *curint; + }; + ++static void ++parse_interface_copy_device(struct device *src, ++ struct parse_interface *dst) ++{ ++ uint32_t broad; ++ struct rt_key key = { 0 }; ++ struct inet6_dev *idev = NULL; ++ struct fib_result res; ++ ++ inquire_device (src, &dst->address, &dst->netmask, ++ &dst->peer, &broad); ++ /* Get gateway */ ++ dst->gateway = INADDR_NONE; ++ key.oif = src->ifindex; ++ if (! main_table->tb_lookup (main_table, &key, &res) ++ && FIB_RES_GW(res) != INADDR_ANY) ++ dst->gateway = FIB_RES_GW (res); ++#ifdef CONFIG_IPV6 ++ if (trivfs_protid_portclasses[PORTCLASS_INET6] != MACH_PORT_NULL) ++ idev = ipv6_find_idev(src); ++ ++ if (idev) ++ { ++ struct inet6_ifaddr *ifa = idev->addr_list; ++ ++ /* Look for IPv6 default router and add it to the interface, ++ * if it belongs to it. ++ */ ++ struct rt6_info *rt6i = ipv6_get_dflt_router(); ++ if (rt6i->rt6i_dev == src) ++ memcpy (&dst->gateway6, &rt6i->rt6i_gateway, sizeof (struct in6_addr)); ++ /* Search for global address and set it in dst */ ++ do ++ { ++ if (!IN6_IS_ADDR_LINKLOCAL (&ifa->addr)) { ++ memcpy (&dst->address6, ifa, sizeof (struct inet6_ifaddr)); ++ break; ++ } ++ } ++ while ((ifa = ifa->if_next)); ++ } ++#endif ++} ++ + /* Adds an empty interface slot to H, and sets H's current interface to it, or + returns an error. */ + static error_t +@@ -122,6 +169,7 @@ parse_hook_add_interface (struct parse_h + (h->num_interfaces + 1) * sizeof (struct parse_interface)); + if (! new) + return ENOMEM; ++ + h->interfaces = new; + h->num_interfaces++; + h->curint = new + h->num_interfaces - 1; +@@ -183,10 +231,16 @@ parse_opt (int opt, char *arg, struct ar + if (addr == INADDR_NONE) PERR (EINVAL, "Malformed %s", type); \ + addr; }) + ++ if (!arg && state->next < state->argc ++ && (*state->argv[state->next] != '-')) ++ { ++ arg = state->argv[state->next]; ++ state->next ++; ++ } ++ + switch (opt) + { +- struct parse_interface *in; +- uint32_t gateway; ++ struct parse_interface *in, *gw4_in; + #ifdef CONFIG_IPV6 + struct parse_interface *gw6_in; + char *ptr; +@@ -217,29 +271,59 @@ parse_opt (int opt, char *arg, struct ar + if (err) + FAIL (err, 10, err, "%s", arg); + ++ /* Set old interface values */ ++ parse_interface_copy_device (in->device, in); + break; + + case 'a': +- h->curint->address = ADDR (arg, "address"); +- if (!IN_CLASSA (ntohl (h->curint->address)) +- && !IN_CLASSB (ntohl (h->curint->address)) +- && !IN_CLASSC (ntohl (h->curint->address))) +- { +- if (IN_MULTICAST (ntohl (h->curint->address))) +- FAIL (EINVAL, 1, 0, +- "%s: Cannot set interface address to multicast address", +- arg); +- else +- FAIL (EINVAL, 1, 0, +- "%s: Illegal or undefined network address", arg); +- } ++ if (arg) ++ { ++ h->curint->address = ADDR (arg, "address"); ++ if (!IN_CLASSA (ntohl (h->curint->address)) ++ && !IN_CLASSB (ntohl (h->curint->address)) ++ && !IN_CLASSC (ntohl (h->curint->address))) ++ { ++ if (IN_MULTICAST (ntohl (h->curint->address))) ++ FAIL (EINVAL, 1, 0, ++ "%s: Cannot set interface address to multicast address", ++ arg); ++ else ++ FAIL (EINVAL, 1, 0, ++ "%s: Illegal or undefined network address", arg); ++ } ++ } else { ++ h->curint->address = ADDR ("0.0.0.0", "address"); ++ h->curint->netmask = ADDR ("255.0.0.0", "netmask"); ++ h->curint->gateway = INADDR_NONE; ++ } + break; ++ + case 'm': +- h->curint->netmask = ADDR (arg, "netmask"); break; ++ if (arg) ++ h->curint->netmask = ADDR (arg, "netmask"); ++ else ++ h->curint->netmask = INADDR_NONE; ++ break; ++ + case 'p': +- h->curint->peer = ADDR (arg, "peer"); break; ++ if (arg) ++ h->curint->peer = ADDR (arg, "peer"); ++ else ++ h->curint->peer = INADDR_NONE; ++ break; ++ + case 'g': +- h->curint->gateway = ADDR (arg, "gateway"); break; ++ if (arg) ++ { ++ /* Remove an possible other default gateway */ ++ for (in = h->interfaces; in < h->interfaces + h->num_interfaces; ++ in++) ++ in->gateway = INADDR_NONE; ++ h->curint->gateway = ADDR (arg, "gateway"); ++ } ++ else ++ h->curint->gateway = INADDR_NONE; ++ break; + + case '4': + pfinet_bind (PORTCLASS_INET, arg); +@@ -254,36 +338,46 @@ parse_opt (int opt, char *arg, struct ar + break; + + case 'A': +- if ((ptr = strchr (arg, '/'))) ++ if (arg) + { +- h->curint->address6.prefix_len = atoi (ptr + 1); +- if (h->curint->address6.prefix_len > 128) +- FAIL (EINVAL, 1, 0, "%s: The prefix-length is invalid", arg); ++ if ((ptr = strchr (arg, '/'))) ++ { ++ h->curint->address6.prefix_len = atoi (ptr + 1); ++ if (h->curint->address6.prefix_len > 128) ++ FAIL (EINVAL, 1, 0, "%s: The prefix-length is invalid", arg); ++ ++ *ptr = 0; ++ } ++ else ++ { ++ h->curint->address6.prefix_len = 64; ++ fprintf (stderr, "No prefix-length given, " ++ "defaulting to %s/64.\n", arg); ++ } + +- *ptr = 0; ++ if (inet_pton (AF_INET6, arg, &h->curint->address6.addr) <= 0) ++ PERR (EINVAL, "Malformed address"); ++ ++ if (IN6_IS_ADDR_MULTICAST (&h->curint->address6.addr)) ++ FAIL (EINVAL, 1, 0, "%s: Cannot set interface address to " ++ "multicast address", arg); + } + else +- { +- h->curint->address6.prefix_len = 64; +- fprintf (stderr, "No prefix-length given, defaulting to %s/64.\n", +- arg); +- } +- +- if (inet_pton (AF_INET6, arg, &h->curint->address6.addr) <= 0) +- PERR (EINVAL, "Malformed address"); +- +- if (IN6_IS_ADDR_MULTICAST (&h->curint->address6.addr)) +- FAIL (EINVAL, 1, 0, "%s: Cannot set interface address to " +- "multicast address", arg); ++ memset (&h->curint->address6, 0, sizeof (struct inet6_ifaddr)); + break; + + case 'G': +- if (inet_pton (AF_INET6, arg, &h->curint->gateway6) <= 0) +- PERR (EINVAL, "Malformed gateway"); ++ if (arg) ++ { ++ if (inet_pton (AF_INET6, arg, &h->curint->gateway6) <= 0) ++ PERR (EINVAL, "Malformed gateway"); + +- if (IN6_IS_ADDR_MULTICAST (&h->curint->gateway6)) +- FAIL (EINVAL, 1, 0, "%s: Cannot set gateway to " +- "multicast address", arg); ++ if (IN6_IS_ADDR_MULTICAST (&h->curint->gateway6)) ++ FAIL (EINVAL, 1, 0, "%s: Cannot set gateway to " ++ "multicast address", arg); ++ } ++ else ++ memset (&h->curint->gateway6, 0, sizeof (struct in6_addr)); + break; + #endif /* CONFIG_IPV6 */ + +@@ -323,20 +417,19 @@ parse_opt (int opt, char *arg, struct ar + /* Specifying a netmask for an address-less interface is a no-no. */ + FAIL (EDESTADDRREQ, 14, 0, "Cannot set netmask"); + #endif +- +- gateway = INADDR_NONE; + #ifdef CONFIG_IPV6 + gw6_in = NULL; + #endif ++ gw4_in = NULL; + for (in = h->interfaces; in < h->interfaces + h->num_interfaces; in++) + { ++ /* delete interface if it doesn't match the actual netmask */ ++ if (! ( (h->curint->address & h->curint->netmask) ++ == (h->curint->gateway & h->curint->netmask))) ++ h->curint->gateway = INADDR_NONE; ++ + if (in->gateway != INADDR_NONE) +- { +- if (gateway != INADDR_NONE) +- FAIL (err, 15, 0, "Cannot have multiple default gateways"); +- gateway = in->gateway; +- in->gateway = INADDR_NONE; +- } ++ gw4_in = in; + + #ifdef CONFIG_IPV6 + if (!IN6_IS_ADDR_UNSPECIFIED (&in->gateway6)) +@@ -361,15 +454,20 @@ parse_opt (int opt, char *arg, struct ar + idev = ipv6_find_idev(in->device); + #endif + +- if (in->address != INADDR_NONE || in->netmask != INADDR_NONE) ++ if (in->address == INADDR_NONE && in->netmask == INADDR_NONE) ++ { ++ h->curint->address = ADDR ("0.0.0.0", "address"); ++ h->curint->netmask = ADDR ("255.0.0.0", "netmask"); ++ } ++ ++ if (in->device) ++ err = configure_device (in->device, in->address, in->netmask, ++ in->peer, INADDR_NONE); ++ ++ if (err) + { +- err = configure_device (in->device, in->address, in->netmask, +- in->peer, INADDR_NONE); +- if (err) +- { +- __mutex_unlock (&global_lock); +- FAIL (err, 16, 0, "cannot configure interface"); +- } ++ __mutex_unlock (&global_lock); ++ FAIL (err, 16, 0, "cannot configure interface"); + } + + #ifdef CONFIG_IPV6 +@@ -377,24 +475,25 @@ parse_opt (int opt, char *arg, struct ar + continue; + + /* First let's remove all non-local addresses. */ +- struct inet6_ifaddr *ifa = idev->addr_list; +- +- while (ifa) +- { +- struct inet6_ifaddr *c_ifa = ifa; +- ifa = ifa->if_next; +- +- if (IN6_ARE_ADDR_EQUAL (&c_ifa->addr, &in->address6.addr)) +- memset (&in->address6, 0, sizeof (struct inet6_ifaddr)); +- +- else if (!IN6_IS_ADDR_LINKLOCAL (&c_ifa->addr) +- && !IN6_IS_ADDR_SITELOCAL (&c_ifa->addr)) +- inet6_addr_del (in->device->ifindex, &c_ifa->addr, +- c_ifa->prefix_len); +- } +- +- if (!IN6_IS_ADDR_UNSPECIFIED (&in->address6.addr)) +- { ++ struct inet6_ifaddr *ifa = idev->addr_list; ++ ++ while (ifa) ++ { ++ struct inet6_ifaddr *c_ifa = ifa; ++ ifa = ifa->if_next; ++ ++ if (!IN6_IS_ADDR_UNSPECIFIED (&in->address6.addr) ++ && IN6_ARE_ADDR_EQUAL (&c_ifa->addr, &in->address6.addr)) ++ memset (&in->address6, 0, sizeof (struct inet6_ifaddr)); ++ ++ else if (!IN6_IS_ADDR_LINKLOCAL (&c_ifa->addr) ++ && !IN6_IS_ADDR_SITELOCAL (&c_ifa->addr)) ++ inet6_addr_del (in->device->ifindex, &c_ifa->addr, ++ c_ifa->prefix_len); ++ } ++ ++ if (!IN6_IS_ADDR_UNSPECIFIED (&in->address6.addr)) ++ { + /* Now assign the new address */ + inet6_addr_add (in->device->ifindex, &in->address6.addr, + in->address6.prefix_len); +@@ -418,33 +517,40 @@ parse_opt (int opt, char *arg, struct ar + req.nlh.nlmsg_seq = 0; + req.nlh.nlmsg_len = NLMSG_LENGTH (sizeof req.rtm); + +- bzero (&req.rtm, sizeof req.rtm); +- bzero (&rta, sizeof rta); ++ memset (&req.rtm, 0, sizeof req.rtm); ++ memset (&rta, 0, sizeof rta); + req.rtm.rtm_scope = RT_SCOPE_UNIVERSE; + req.rtm.rtm_type = RTN_UNICAST; + req.rtm.rtm_protocol = RTPROT_STATIC; +- rta.rta_gw = &gateway; + +- if (gateway == INADDR_NONE) ++ if (!gw4_in) + { +- /* Delete any existing default route. */ +- req.nlh.nlmsg_type = RTM_DELROUTE; +- req.nlh.nlmsg_flags = 0; +- tb = fib_get_table (req.rtm.rtm_table); +- if (tb) +- { +- err = - (*tb->tb_delete) (tb, &req.rtm, &rta, &req.nlh, 0); +- if (err && err != ESRCH) +- { +- __mutex_unlock (&global_lock); +- FAIL (err, 17, 0, "cannot remove old default gateway"); +- } +- err = 0; +- } ++ /* Delete any existing default route on configured devices */ ++ for (in = h->interfaces; in < h->interfaces + h->num_interfaces; ++ in++) { ++ req.nlh.nlmsg_type = RTM_DELROUTE; ++ req.nlh.nlmsg_flags = 0; ++ rta.rta_oif = &in->device->ifindex; ++ tb = fib_get_table (req.rtm.rtm_table); ++ if (tb) ++ { ++ err = - (*tb->tb_delete) ++ (tb, &req.rtm, &rta, &req.nlh, 0); ++ if (err && err != ESRCH) ++ { ++ __mutex_unlock (&global_lock); ++ FAIL (err, 17, 0, ++ "cannot remove old default gateway"); ++ } ++ err = 0; ++ } ++ } + } + else + { + /* Add a default route, replacing any existing one. */ ++ rta.rta_oif = &gw4_in->device->ifindex; ++ rta.rta_gw = &gw4_in->gateway; + req.nlh.nlmsg_type = RTM_NEWROUTE; + req.nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_REPLACE; + tb = fib_new_table (req.rtm.rtm_table); +@@ -467,13 +573,77 @@ parse_opt (int opt, char *arg, struct ar + if (!gw6_in || rt6i->rt6i_dev != gw6_in->device + || !IN6_ARE_ADDR_EQUAL (&rt6i->rt6i_gateway, &gw6_in->gateway6)) + { +- rt6_purge_dflt_routers (0); ++ /* Delete any existing default route on configured devices */ ++ for (in = h->interfaces; in < h->interfaces ++ + h->num_interfaces; in++) ++ if (rt6i->rt6i_dev == in->device || gw6_in ) ++ rt6_purge_dflt_routers (0); ++ + if (gw6_in) + rt6_add_dflt_router (&gw6_in->gateway6, gw6_in->device); + } + } + #endif + ++ /* Setup the routing required for DHCP. */ ++ for (in = h->interfaces; in < h->interfaces + h->num_interfaces; in++) ++ { ++ struct kern_rta rta; ++ struct ++ { ++ struct nlmsghdr nlh; ++ struct rtmsg rtm; ++ } req; ++ struct fib_table *tb; ++ struct rtentry route; ++ struct sockaddr_in *dst; ++ struct device *dev; ++ ++ if (!in->device) ++ continue; ++ ++ dst = (struct sockaddr_in *) &route.rt_dst; ++ if (!in->device->name) ++ { ++ __mutex_unlock (&global_lock); ++ FAIL (ENODEV, 17, 0, "unknown device"); ++ } ++ dev = dev_get (in->device->name); ++ if (!dev) ++ { ++ __mutex_unlock (&global_lock); ++ FAIL (ENODEV, 17, 0, "unknown device"); ++ } ++ ++ /* Simulate the SIOCADDRT behavior. */ ++ memset (&route, 0, sizeof (struct rtentry)); ++ memset (&req.rtm, 0, sizeof req.rtm); ++ memset (&rta, 0, sizeof rta); ++ req.nlh.nlmsg_type = RTM_NEWROUTE; ++ ++ /* Append this routing for 0.0.0.0. By this way we can send always ++ dhcp messages (e.g dhcp renew). */ ++ req.nlh.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE ++ | NLM_F_APPEND; ++ req.rtm.rtm_protocol = RTPROT_BOOT; ++ req.rtm.rtm_scope = RT_SCOPE_LINK; ++ req.rtm.rtm_type = RTN_UNICAST; ++ rta.rta_dst = &dst->sin_addr.s_addr; ++ rta.rta_oif = &dev->ifindex; ++ ++ tb = fib_new_table (req.rtm.rtm_table); ++ if (tb) ++ err = tb->tb_insert (tb, &req.rtm, &rta, &req.nlh, NULL); ++ else ++ err = ENOBUFS; ++ ++ if (err) ++ { ++ __mutex_unlock (&global_lock); ++ FAIL (err, 17, 0, "cannot add route"); ++ } ++ } ++ + __mutex_unlock (&global_lock); + + /* Fall through to free hook. */ +@@ -526,8 +696,9 @@ trivfs_append_args (struct trivfs_contro + ADD_ADDR_OPT ("netmask", mask); + if (peer != addr) + ADD_ADDR_OPT ("peer", peer); +- key.iif = dev->ifindex; +- if (! main_table->tb_lookup (main_table, &key, &res)) ++ key.oif = dev->ifindex; ++ if (! main_table->tb_lookup (main_table, &key, &res) ++ && FIB_RES_GW(res) != INADDR_ANY) + ADD_ADDR_OPT ("gateway", FIB_RES_GW (res)); + + #undef ADD_ADDR_OPT +--- a/pfinet/linux-src/net/ipv4/devinet.c ++++ b/pfinet/linux-src/net/ipv4/devinet.c +@@ -214,10 +214,12 @@ inet_insert_ifa(struct in_device *in_dev + { + struct in_ifaddr *ifa1, **ifap, **last_primary; + ++#ifndef _HURD_ + if (ifa->ifa_local == 0) { + inet_free_ifa(ifa); + return 0; + } ++#endif + + ifa->ifa_flags &= ~IFA_F_SECONDARY; + last_primary = &in_dev->ifa_list; diff --git a/debian/patches/pflocal.patch b/debian/patches/pflocal.patch new file mode 100644 index 00000000..3d9b3ac2 --- /dev/null +++ b/debian/patches/pflocal.patch @@ -0,0 +1,674 @@ +2005-05-17 Neal H. Walfield <neal@gnu.org> + + * connq.h (struct connq_request): Remove forward. + (connq_listen): Wait for a request to be queued not until there is + a connection attempt. Remove REQ parameter. Update callers. + (connq_request_complete): Remove declaration. + (connq_connect): Wait for a slot to queue a request not until + there is an acceptor. Remove SOCK parameter. Update callers. + (connq_connect_complete): New declaration. + (connq_connect_cancel): New declaration. + + * connq.c (struct connq): Remove fields noqueue, queue, length, + head and tail. Add fields head, tail, count, max, connectors and + num_connectors. That is, replace the circular buffer with a + singly linked list. + (qnext): Remove function. + (struct connq_request): Remove field signal, lock, completed and + err. Add field next. + (connq_request_init): Rewrite according to new semantics. + (connq_request_enqueue): New function. + (connq_request_dequeue): New function. + (connq_create): Update according to new semantics. + (connq_destroy): Likewise. + (connq_listen): Rewrite to not block until there is a connector + but until there is a request in the queue. + (connq_request_complete): Remove function. + (connq_connect): Rewrite to not block until there is an acceptor + but until there is space for a request. + (connq_connect_complete): New function. + (connq_connect_cancel): New function. + (connq_compress): Remove dead code. + (connq_set_length): Rewrite. + + * socket.c (S_socket_connect): Create the server socket here... + (S_socket_accept): ... not here. + +--- + pflocal/connq.c | 341 +++++++++++++++++++++++++++++-------------------------- + pflocal/connq.h | 39 +++--- + pflocal/io.c | 8 - + pflocal/socket.c | 72 +++++------ + 4 files changed, 245 insertions(+), 215 deletions(-) + +--- a/pflocal/connq.c ++++ b/pflocal/connq.c +@@ -26,31 +26,22 @@ + /* A queue for queueing incoming connections. */ + struct connq + { +- /* True if all connection requests should be treated as non-blocking. */ +- int noqueue; +- + /* The connection request queue. */ +- struct connq_request **queue; +- unsigned length; +- /* Head is the position in QUEUE of the first request, and TAIL is the +- first free position in the queue. If HEAD == TAIL, then the queue is +- empty. Starting at HEAD, successive positions can be calculated by +- using qnext(). */ +- unsigned head, tail; ++ struct connq_request *head; ++ struct connq_request **tail; ++ unsigned count; ++ unsigned max; + + /* Threads that have done an accept on this queue wait on this condition. */ + struct condition listeners; + unsigned num_listeners; + ++ /* Threads that have done a connect on this queue wait on this condition. */ ++ struct condition connectors; ++ unsigned num_connectors; ++ + struct mutex lock; + }; +- +-/* Returns the position CQ's queue after POS. */ +-static inline unsigned +-qnext (struct connq *cq, unsigned pos) +-{ +- return (pos + 1 == cq->length) ? 0 : pos + 1; +-} + + /* ---------------------------------------------------------------- */ + +@@ -58,30 +49,50 @@ qnext (struct connq *cq, unsigned pos) + get information from and to the thread. */ + struct connq_request + { ++ struct connq_request *next; ++ + /* The socket that's waiting to connect. */ + struct sock *sock; +- +- /* What the waiting thread blocks on. */ +- struct condition signal; +- struct mutex lock; +- +- /* Set to true when this request has been dealt with, to guard against +- spurious conditions being signaled. */ +- int completed; +- +- /* After the waiting thread is unblocked, this is the result, either 0 if +- SOCK has been connected, or an error. */ +- error_t err; + }; + + static inline void + connq_request_init (struct connq_request *req, struct sock *sock) + { +- req->err = 0; + req->sock = sock; +- req->completed = 0; +- condition_init (&req->signal); +- mutex_init (&req->lock); ++} ++ ++/* Enqueue connection request REQ onto CQ. CQ must be locked. */ ++static void ++connq_request_enqueue (struct connq *cq, struct connq_request *req) ++{ ++ assert (! mutex_try_lock (&cq->lock)); ++ ++ req->next = NULL; ++ *cq->tail = req; ++ cq->tail = &req->next; ++ ++ cq->count ++; ++} ++ ++/* Dequeue a pending request from CQ. CQ must be locked and must not ++ be empty. */ ++static struct connq_request * ++connq_request_dequeue (struct connq *cq) ++{ ++ struct connq_request *req; ++ ++ assert (! mutex_try_lock (&cq->lock)); ++ assert (cq->head); ++ ++ req = cq->head; ++ cq->head = req->next; ++ if (! cq->head) ++ /* We just dequeued the last element. Fixup the tail pointer. */ ++ cq->tail = &cq->head; ++ ++ cq->count --; ++ ++ return req; + } + + /* ---------------------------------------------------------------- */ +@@ -95,16 +106,20 @@ connq_create (struct connq **cq) + struct connq *new = malloc (sizeof (struct connq)); + + if (!new) +- return ENOMEM; ++ return ENOBUFS; ++ ++ new->head = NULL; ++ new->tail = &new->head; ++ new->count = 0; ++ /* By default, don't queue requests. */ ++ new->max = 0; + +- new->noqueue = 1; /* By default, don't queue requests. */ +- new->length = 0; +- new->head = new->tail = 0; +- new->queue = NULL; + new->num_listeners = 0; ++ new->num_connectors = 0; + + mutex_init (&new->lock); + condition_init (&new->listeners); ++ condition_init (&new->connectors); + + *cq = new; + return 0; +@@ -116,175 +131,189 @@ connq_destroy (struct connq *cq) + { + /* Everybody in the queue should hold a reference to the socket + containing the queue. */ +- assert (cq->length == 0); +- /* Nevertheless, malloc(0) or realloc(0) might allocate some small +- space. */ +- if (cq->queue) +- free (cq->queue); ++ assert (! cq->head); ++ assert (cq->count == 0); ++ + free (cq); + } + + /* ---------------------------------------------------------------- */ + +-/* Wait for a connection attempt to be made on CQ, and return the connecting +- socket in SOCK, and a request tag in REQ. If REQ is NULL, the request is +- left in the queue, otherwise connq_request_complete must be called on REQ +- to allow the requesting thread to continue. If NOBLOCK is true, +- EWOULDBLOCK is returned when there are no immediate connections +- available. */ ++/* Return a connection request on CQ. If SOCK is NULL, the request is ++ left in the queue. If NOBLOCK is true, EWOULDBLOCK is returned ++ when there are no immediate connections available. */ + error_t +-connq_listen (struct connq *cq, int noblock, +- struct connq_request **req, struct sock **sock) ++connq_listen (struct connq *cq, int noblock, struct sock **sock) + { ++ error_t err = 0; ++ + mutex_lock (&cq->lock); + +- if (noblock && cq->head == cq->tail) ++ if (noblock && cq->count == 0 && cq->num_connectors == 0) + { + mutex_unlock (&cq->lock); + return EWOULDBLOCK; + } + ++ if (! sock && (cq->count > 0 || cq->num_connectors > 0)) ++ /* The caller just wants to know if a connection ready. */ ++ { ++ mutex_unlock (&cq->lock); ++ return 0; ++ } ++ + cq->num_listeners++; + +- while (cq->head == cq->tail) +- if (hurd_condition_wait (&cq->listeners, &cq->lock)) +- { +- cq->num_listeners--; +- mutex_unlock (&cq->lock); +- return EINTR; +- } ++ if (cq->count == 0) ++ /* The request queue is empty. */ ++ { ++ assert (! cq->head); ++ ++ if (cq->num_connectors > 0) ++ /* Someone is waiting for an acceptor. Signal that we can ++ service their request. */ ++ condition_signal (&cq->connectors); ++ ++ do ++ if (hurd_condition_wait (&cq->listeners, &cq->lock)) ++ { ++ cq->num_listeners--; ++ err = EINTR; ++ goto out; ++ } ++ while (cq->count == 0); ++ } ++ ++ assert (cq->head); + +- if (req != NULL) ++ if (sock) + /* Dequeue the next request, if desired. */ + { +- *req = cq->queue[cq->head]; +- cq->head = qnext (cq, cq->head); +- if (sock != NULL) +- *sock = (*req)->sock; ++ struct connq_request *req = connq_request_dequeue (cq); ++ *sock = req->sock; ++ free (req); + } ++ else if (cq->num_listeners > 0) ++ /* The caller will not actually process this request but someone ++ else could. (This case is rare but possible: it would require ++ one thread to do a select on the socket and a second to do an ++ accept.) */ ++ condition_signal (&cq->listeners); ++ else ++ /* There is no one else to process the request and the connection ++ has now been initiated. This is not actually a problem as even ++ if the current queue limit is 0, the connector will queue the ++ request and another listener (should) eventually come along. ++ (In fact it is very probably as the caller has likely done a ++ select and will now follow up with an accept.) */ ++ ; + +- cq->num_listeners--; +- ++ out: + mutex_unlock (&cq->lock); +- +- return 0; +-} +- +-/* Return the error code ERR to the thread that made the listen request REQ, +- returned from a previous connq_listen. */ +-void +-connq_request_complete (struct connq_request *req, error_t err) +-{ +- mutex_lock (&req->lock); +- req->err = err; +- req->completed = 1; +- condition_signal (&req->signal); +- mutex_unlock (&req->lock); ++ return err; + } + +-/* Try to connect SOCK with the socket listening on CQ. If NOBLOCK is true, +- then return EWOULDBLOCK immediately when there are no immediate +- connections available. Neither SOCK nor CQ should be locked. */ ++/* Try to connect SOCK with the socket listening on CQ. If NOBLOCK is ++ true, then return EWOULDBLOCK if there are no connections ++ immediately available. On success, this call must be followed up ++ either connq_connect_complete or connq_connect_cancel. */ + error_t +-connq_connect (struct connq *cq, int noblock, struct sock *sock) ++connq_connect (struct connq *cq, int noblock) + { +- error_t err = 0; +- unsigned next; +- + mutex_lock (&cq->lock); + + /* Check for listeners after we've locked CQ for good. */ +- if ((noblock || cq->noqueue) && cq->num_listeners == 0) ++ ++ if (noblock ++ && cq->count + cq->num_connectors >= cq->max + cq->num_listeners) ++ /* We are in non-blocking mode and would have to wait to secure an ++ entry in the listen queue. */ + { + mutex_unlock (&cq->lock); + return EWOULDBLOCK; + } + +- next = qnext (cq, cq->tail); +- if (next == cq->tail) +- /* The queue is full. */ +- err = ECONNREFUSED; +- else +- { +- struct connq_request req; ++ cq->num_connectors ++; ++ ++ while (cq->count + cq->num_connectors > cq->max + cq->num_listeners) ++ /* The queue is full and there is no immediate listener to service ++ us. Block until we can get a slot. */ ++ if (hurd_condition_wait (&cq->connectors, &cq->lock)) ++ { ++ cq->num_connectors --; ++ mutex_unlock (&cq->lock); ++ return EINTR; ++ } + +- connq_request_init (&req, sock); ++ mutex_unlock (&cq->lock); + +- cq->queue[cq->tail] = &req; +- cq->tail = next; ++ return 0; ++} + +- /* Hold REQ.LOCK before we signal the condition so that we're sure +- to be woken up. */ +- mutex_lock (&req.lock); +- condition_signal (&cq->listeners); +- mutex_unlock (&cq->lock); ++/* Follow up to connq_connect. Completes the connect, SOCK is the new ++ server socket. */ ++void ++connq_connect_complete (struct connq *cq, struct sock *sock) ++{ ++ struct connq_request *req; ++ ++ req = malloc (sizeof (struct connq_request)); ++ if (! req) ++ abort (); ++ ++ connq_request_init (req, sock); + +- while (!req.completed) +- condition_wait (&req.signal, &req.lock); +- err = req.err; ++ mutex_lock (&cq->lock); ++ ++ assert (cq->num_connectors > 0); ++ cq->num_connectors --; ++ ++ connq_request_enqueue (cq, req); + +- mutex_unlock (&req.lock); ++ if (cq->num_listeners > 0) ++ /* Wake a listener up. We must consume the listener ref here as ++ someone else might call this function before the listener ++ thread dequeues this request. */ ++ { ++ cq->num_listeners --; ++ condition_signal (&cq->listeners); + } + +- return err; ++ mutex_unlock (&cq->lock); + } +- +-#if 0 +-/* `Compresses' CQ, by removing any NULL entries. CQ should be locked. */ +-static void +-connq_compress (struct connq *cq) ++ ++/* Follow up to connq_connect. Cancel the connect. */ ++void ++connq_connect_cancel (struct connq *cq) + { +- unsigned pos; +- unsigned comp_tail = cq->head; ++ mutex_lock (&cq->lock); + +- /* Now compress the queue to remove any null entries we put in. */ +- for (pos = cq->head; pos != cq->tail; pos = qnext (cq, pos)) +- if (cq->queue[pos] != NULL) +- /* This position has a non-NULL request, so move it to the end of the +- compressed queue. */ +- { +- cq->queue[comp_tail] = cq->queue[pos]; +- comp_tail = qnext (cq, comp_tail); +- } ++ assert (cq->num_connectors > 0); ++ cq->num_connectors --; + +- /* Move back tail to only include what we kept in the queue. */ +- cq->tail = comp_tail; ++ if (cq->count + cq->num_connectors >= cq->max + cq->num_listeners) ++ /* A connector is blocked and could use the spot we reserved. */ ++ condition_signal (&cq->connectors); ++ ++ mutex_unlock (&cq->lock); + } +-#endif + +-/* Set CQ's queue length to LENGTH. Any sockets already waiting for a +- connections that are past the new length will fail with ECONNREFUSED. */ ++/* Set CQ's queue length to LENGTH. */ + error_t +-connq_set_length (struct connq *cq, int length) ++connq_set_length (struct connq *cq, int max) + { +- mutex_lock (&cq->lock); ++ int omax; + +- if (length > cq->length) +- /* Growing the queue is simple... */ +- cq->queue = realloc (cq->queue, sizeof (struct connq_request *) * length); +- else +- /* Shrinking it less so. */ +- { +- int i; +- struct connq_request **new_queue = +- malloc (sizeof (struct connq_request *) * length); +- +- for (i = 0; i < cq->length && cq->head != cq->tail; i++) +- { +- if (i < length) +- /* Keep this connect request in the queue. */ +- new_queue[length - i] = cq->queue[cq->head]; +- else +- /* Punt this one. */ +- connq_request_complete (cq->queue[cq->head], ECONNREFUSED); +- cq->head = qnext (cq, cq->head); +- } +- +- free (cq->queue); +- cq->queue = new_queue; +- } ++ mutex_lock (&cq->lock); ++ omax = cq->max; ++ cq->max = max; + +- cq->noqueue = 0; /* Turn on queueing. */ ++ if (max > omax && cq->count >= omax && cq->count < max ++ && cq->num_connectors >= cq->num_listeners) ++ /* This is an increase in the number of connection slots which has ++ made some slots available and there are waiting threads. Wake ++ them up. */ ++ condition_broadcast (&cq->listeners); + + mutex_unlock (&cq->lock); + +--- a/pflocal/connq.h ++++ b/pflocal/connq.h +@@ -23,9 +23,8 @@ + + #include <errno.h> + +-/* Unknown types */ ++/* Forward. */ + struct connq; +-struct connq_request; + struct sock; + + /* Create a new listening queue, returning it in CQ. The resulting queue +@@ -36,26 +35,26 @@ error_t connq_create (struct connq **cq) + /* Destroy a queue. */ + void connq_destroy (struct connq *cq); + +-/* Wait for a connection attempt to be made on CQ, and return the connecting +- socket in SOCK, and a request tag in REQ. If REQ is NULL, the request is +- left in the queue, otherwise connq_request_complete must be called on REQ +- to allow the requesting thread to continue. If NOBLOCK is true, +- EWOULDBLOCK is returned when there are no immediate connections +- available. CQ should be unlocked. */ +-error_t connq_listen (struct connq *cq, int noblock, +- struct connq_request **req, struct sock **sock); +- +-/* Return the error code ERR to the thread that made the listen request REQ, +- returned from a previous connq_listen. */ +-void connq_request_complete (struct connq_request *req, error_t err); ++/* Return a connection request on CQ. If SOCK is NULL, the request is ++ left in the queue. If NOBLOCK is true, EWOULDBLOCK is returned ++ when there are no immediate connections available. */ ++error_t connq_listen (struct connq *cq, int noblock, struct sock **sock); ++ ++/* Try to connect SOCK with the socket listening on CQ. If NOBLOCK is ++ true, then return EWOULDBLOCK if there are no connections ++ immediately available. On success, this call must be followed up ++ either connq_connect_complete or connq_connect_cancel. */ ++error_t connq_connect (struct connq *cq, int noblock); ++ ++/* Follow up to connq_connect. Completes the connection, SOCK is the ++ new server socket. */ ++void connq_connect_complete (struct connq *cq, struct sock *sock); ++ ++/* Follow up to connq_connect. Cancel the connect. */ ++void connq_connect_cancel (struct connq *cq); + + /* Set CQ's queue length to LENGTH. Any sockets already waiting for a +- connections that are past the new length will fail with ECONNREFUSED. */ ++ connections that are past the new length remain. */ + error_t connq_set_length (struct connq *cq, int length); + +-/* Try to connect SOCK with the socket listening on CQ. If NOBLOCK is true, +- then return EWOULDBLOCK immediately when there are no immediate +- connections available. Neither SOCK nor CQ should be locked. */ +-error_t connq_connect (struct connq *cq, int noblock, struct sock *sock); +- + #endif /* __CONNQ_H__ */ +--- a/pflocal/io.c ++++ b/pflocal/io.c +@@ -199,16 +199,16 @@ S_io_select (struct sock_user *user, + + if (*select_type & SELECT_READ) + { +- /* Wait for a connect. Passing in NULL for REQ means that the +- request won't be dequeued. */ +- if (connq_listen (sock->listen_queue, 1, NULL, NULL) == 0) ++ /* Wait for a connect. Passing in NULL for SOCK means that ++ the request won't be dequeued. */ ++ if (connq_listen (sock->listen_queue, 1, NULL) == 0) + /* We can satisfy this request immediately. */ + return 0; + else + /* Gotta wait... */ + { + ports_interrupt_self_on_port_death (user, reply); +- return connq_listen (sock->listen_queue, 0, NULL, NULL); ++ return connq_listen (sock->listen_queue, 0, NULL); + } + } + } +--- a/pflocal/socket.c ++++ b/pflocal/socket.c +@@ -110,7 +110,7 @@ S_socket_connect (struct sock_user *user + else if (sock->flags & SOCK_CONNECTED) + /* SOCK_CONNECTED is only set for connection-oriented sockets, + which can only ever connect once. [If we didn't do this test +- here, it would eventually fail when it the listening socket ++ here, it would eventually fail when the listening socket + tried to accept our connection request.] */ + err = EISCONN; + else +@@ -118,16 +118,35 @@ S_socket_connect (struct sock_user *user + /* Assert that we're trying to connect, so anyone else trying + to do so will fail with EALREADY. */ + sock->connect_queue = cq; +- mutex_unlock (&sock->lock); /* Unlock SOCK while waiting. */ ++ /* Unlock SOCK while waiting. */ ++ mutex_unlock (&sock->lock); + +- /* Try to connect. */ +- err = connq_connect (cq, sock->flags & SOCK_NONBLOCK, sock); ++ err = connq_connect (peer->listen_queue, ++ sock->flags & SOCK_NONBLOCK); ++ if (!err) ++ { ++ struct sock *server; ++ ++ err = sock_clone (peer, &server); ++ if (!err) ++ { ++ err = sock_connect (sock, server); ++ if (!err) ++ connq_connect_complete (peer->listen_queue, server); ++ else ++ sock_free (server); ++ } + +- /* We can safely set CONNECT_QUEUE to NULL, as no one else can ++ mutex_lock (&sock->lock); ++ if (err) ++ connq_connect_cancel (peer->listen_queue); ++ } ++ ++ /* We must set CONNECT_QUEUE to NULL, as no one else can + set it until we've done so. */ +- mutex_lock (&sock->lock); + sock->connect_queue = NULL; + } ++ + mutex_unlock (&sock->lock); + } + else +@@ -157,42 +176,25 @@ S_socket_accept (struct sock_user *user, + err = ensure_connq (sock); + if (!err) + { +- struct connq_request *req; + struct sock *peer_sock; + +- err = +- connq_listen (sock->listen_queue, sock->flags & SOCK_NONBLOCK, +- &req, &peer_sock); ++ err = connq_listen (sock->listen_queue, sock->flags & SOCK_NONBLOCK, ++ &peer_sock); + if (!err) + { +- struct sock *conn_sock; +- +- err = sock_clone (sock, &conn_sock); ++ struct addr *peer_addr; ++ *port_type = MACH_MSG_TYPE_MAKE_SEND; ++ err = sock_create_port (peer_sock, port); ++ if (!err) ++ err = sock_get_addr (peer_sock, &peer_addr); + if (!err) + { +- err = sock_connect (conn_sock, peer_sock); +- if (!err) +- { +- struct addr *peer_addr; +- *port_type = MACH_MSG_TYPE_MAKE_SEND; +- err = sock_create_port (conn_sock, port); +- if (!err) +- err = sock_get_addr (peer_sock, &peer_addr); +- if (!err) +- { +- *peer_addr_port = ports_get_right (peer_addr); +- *peer_addr_port_type = MACH_MSG_TYPE_MAKE_SEND; +- ports_port_deref (peer_addr); +- } +- else +- /* TEAR DOWN THE CONNECTION XXX */; +- } +- if (err) +- sock_free (conn_sock); ++ *peer_addr_port = ports_get_right (peer_addr); ++ *peer_addr_port_type = MACH_MSG_TYPE_MAKE_SEND; ++ ports_port_deref (peer_addr); + } +- +- /* Communicate any error (or success) to the connecting thread. */ +- connq_request_complete (req, err); ++ else ++ /* TEAR DOWN THE CONNECTION XXX */; + } + } + diff --git a/debian/patches/posix-sigcodes.patch b/debian/patches/posix-sigcodes.patch new file mode 100644 index 00000000..34e089f2 --- /dev/null +++ b/debian/patches/posix-sigcodes.patch @@ -0,0 +1,270 @@ +commit 2a54ebafd46a26d537ac38d46dc82568f751cc42 +Author: Jeremie Koenig <jk@jk.fr.eu.org> +Date: Wed Jun 8 03:00:37 2011 +0000 + + proc: send signals with POSIX sigcodes + + * proc/stubs.c (send_signal): Add a sigcode argument. + * proc/proc.h (send_signal): Declare the sigcode argument. + * proc/pgrp.c (leave_pgrp): Specify a null sigcode. + * proc/wait.c (alert_parent): Use CLD_EXITED for SIGCHLD on exit. + (S_proc_mark_stop): Use CLD_STOPPED for SIGCHLD on stop. + +diff --git a/proc/pgrp.c b/proc/pgrp.c +index 2d6ca93..72c09ba 100644 +--- a/proc/pgrp.c ++++ b/proc/pgrp.c +@@ -399,42 +399,42 @@ leave_pgrp (struct proc *p) + else if (p->p_parent->p_pgrp != pg + && p->p_parent->p_pgrp->pg_session == pg->pg_session + && !--pg->pg_orphcnt) + { + /* We were the last process keeping this from being + an orphaned process group -- do the orphaning gook */ + struct proc *ip; + int dosignal = 0; + + for (ip = pg->pg_plist; ip; ip = ip->p_gnext) + { + if (ip->p_stopped) + dosignal = 1; + if (ip->p_msgport != MACH_PORT_NULL) + nowait_msg_proc_newids (ip->p_msgport, ip->p_task, ip->p_parent->p_pid, + ip->p_pid, 1); + } + if (dosignal) + for (ip = pg->pg_plist; ip; ip = ip->p_gnext) + { +- send_signal (ip->p_msgport, SIGHUP, ip->p_task); +- send_signal (ip->p_msgport, SIGCONT, ip->p_task); ++ send_signal (ip->p_msgport, SIGHUP, 0, ip->p_task); ++ send_signal (ip->p_msgport, SIGCONT, 0, ip->p_task); + } + } + } + + /* Cause process P to join its process group. */ + void + join_pgrp (struct proc *p) + { + struct pgrp *pg = p->p_pgrp; + struct proc *tp; + int origorphcnt; + + p->p_gnext = pg->pg_plist; + p->p_gprevp = &pg->pg_plist; + if (pg->pg_plist) + pg->pg_plist->p_gprevp = &p->p_gnext; + pg->pg_plist = p; + + origorphcnt = !!pg->pg_orphcnt; + if (p->p_parent->p_pgrp != pg +diff --git a/proc/proc.h b/proc/proc.h +index 7943e0b..b52ca1d 100644 +--- a/proc/proc.h ++++ b/proc/proc.h +@@ -192,24 +192,24 @@ void exc_clean (void *); + + struct proc *add_tasks (task_t); + int pidfree (pid_t); + + struct proc *create_startup_proc (void); + struct proc *allocate_proc (task_t); + void proc_death_notify (struct proc *); + void complete_proc (struct proc *, pid_t); + + void leave_pgrp (struct proc *); + void join_pgrp (struct proc *); + void boot_setsid (struct proc *); + + void process_has_exited (struct proc *); + void alert_parent (struct proc *); + void reparent_zombies (struct proc *); + void complete_exit (struct proc *); + + void initialize_version_info (void); + +-void send_signal (mach_port_t, int, mach_port_t); ++void send_signal (mach_port_t, int, int, mach_port_t); + + + #endif +diff --git a/proc/stubs.c b/proc/stubs.c +index de3a9b1..ee8e578 100644 +--- a/proc/stubs.c ++++ b/proc/stubs.c +@@ -59,40 +59,41 @@ blocking_message_send (any_t arg) + case MACH_SEND_INTERRUPTED: + case MACH_SEND_INVALID_NOTIFY: + case MACH_SEND_NO_NOTIFY: + case MACH_SEND_NOTIFY_IN_PROGRESS: + assert_perror (err); + break; + + default: /* Other errors are safe to ignore. */ + break; + } + + + return 0; + } + + /* Send signal SIGNO to MSGPORT with REFPORT as reference. Don't + block in any fashion. */ + void + send_signal (mach_port_t msgport, + int signal, ++ int sigcode, + mach_port_t refport) + { + error_t err; + + /* This message buffer might be modified by mach_msg in some error cases, + so we cannot safely use a shared static buffer. */ + struct msg_sig_post_request message = + { + { + /* Message header: */ + (MACH_MSGH_BITS_COMPLEX + | MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, + MACH_MSG_TYPE_MAKE_SEND_ONCE)), /* msgh_bits */ + sizeof message, /* msgh_size */ + msgport, /* msgh_remote_port */ + MACH_PORT_NULL, /* msgh_local_port */ + 0, /* msgh_seqno */ + RPCID_SIG_POST, /* msgh_id */ + }, + { +@@ -101,41 +102,41 @@ send_signal (mach_port_t msgport, + 32, /* msgt_size */ + 1, /* msgt_number */ + 1, /* msgt_inline */ + 0, /* msgt_longform */ + 0, /* msgt_deallocate */ + 0, /* msgt_unused */ + }, + /* Signal number */ + signal, + /* Type descriptor for sigcode */ + { + MACH_MSG_TYPE_INTEGER_32, /* msgt_name */ + 32, /* msgt_size */ + 1, /* msgt_number */ + 1, /* msgt_inline */ + 0, /* msgt_longform */ + 0, /* msgt_deallocate */ + 0, /* msgt_unused */ + }, + /* Sigcode */ +- 0, ++ sigcode, + { + /* Type descriptor for refport */ + MACH_MSG_TYPE_COPY_SEND, /* msgt_name */ + 32, /* msgt_size */ + 1, /* msgt_number */ + 1, /* msgt_inline */ + 0, /* msgt_longform */ + 0, /* msgt_deallocate */ + 0, /* msgt_unused */ + }, + refport + }; + + err = mach_msg ((mach_msg_header_t *)&message, + MACH_SEND_MSG|MACH_SEND_TIMEOUT, sizeof message, 0, + MACH_PORT_NULL, 0, MACH_PORT_NULL); + switch (err) + { + case MACH_SEND_TIMED_OUT: + /* The send could not complete immediately, and we do not want to +diff --git a/proc/wait.c b/proc/wait.c +index 6fc94e8..332aaf6 100644 +--- a/proc/wait.c ++++ b/proc/wait.c +@@ -127,41 +127,41 @@ sample_rusage (struct proc *p) + /* Return nonzero if a `waitpid' on WAIT_PID by a process + in MYPGRP cares about the death of PID/PGRP. */ + static inline int + waiter_cares (pid_t wait_pid, pid_t mypgrp, + pid_t pid, pid_t pgrp) + { + return (wait_pid == pid || + wait_pid == -pgrp || + wait_pid == WAIT_ANY || + (wait_pid == WAIT_MYPGRP && pgrp == mypgrp)); + } + + /* A process is dying. Send SIGCHLD to the parent. + Wake the parent if it is waiting for us to exit. */ + void + alert_parent (struct proc *p) + { + /* We accumulate the aggregate usage stats of all our dead children. */ + rusage_add (&p->p_parent->p_child_rusage, &p->p_rusage); + +- send_signal (p->p_parent->p_msgport, SIGCHLD, p->p_parent->p_task); ++ send_signal (p->p_parent->p_msgport, SIGCHLD, CLD_EXITED, p->p_parent->p_task); + + if (!p->p_exiting) + { + p->p_status = W_EXITCODE (0, SIGKILL); + p->p_sigcode = -1; + } + + if (p->p_parent->p_waiting) + { + condition_broadcast (&p->p_parent->p_wakeup); + p->p_parent->p_waiting = 0; + } + } + + kern_return_t + S_proc_wait (struct proc *p, + mach_port_t reply_port, + mach_msg_type_name_t reply_port_type, + pid_t pid, + int options, +@@ -240,41 +240,41 @@ S_proc_wait (struct proc *p, + kern_return_t + S_proc_mark_stop (struct proc *p, + int signo, + int sigcode) + { + if (!p) + return EOPNOTSUPP; + + p->p_stopped = 1; + p->p_status = W_STOPCODE (signo); + p->p_sigcode = sigcode; + p->p_waited = 0; + + if (p->p_parent->p_waiting) + { + condition_broadcast (&p->p_parent->p_wakeup); + p->p_parent->p_waiting = 0; + } + + if (!p->p_parent->p_nostopcld) +- send_signal (p->p_parent->p_msgport, SIGCHLD, p->p_parent->p_task); ++ send_signal (p->p_parent->p_msgport, SIGCHLD, CLD_STOPPED, p->p_parent->p_task); + + return 0; + } + + /* Implement proc_mark_exit as described in <hurd/process.defs>. */ + kern_return_t + S_proc_mark_exit (struct proc *p, + int status, + int sigcode) + { + if (!p) + return EOPNOTSUPP; + + if (WIFSTOPPED (status)) + return EINVAL; + + sample_rusage (p); /* See comments above sample_rusage. */ + + if (p->p_exiting) + return EBUSY; diff --git a/debian/patches/proxy-defpager.diff b/debian/patches/proxy-defpager.diff new file mode 100644 index 00000000..0ba12dee --- /dev/null +++ b/debian/patches/proxy-defpager.diff @@ -0,0 +1,59 @@ +https://savannah.gnu.org/bugs/?26751 + +2009-06-07 Zheng Da <zhengda1936@gmail.com> + + * Makefile: Use customized default_pager.defs. + + * proxy-defpager.c: Include customized default_pager header. + +--- + Makefile | 7 +++++-- + proxy-defpager.c | 5 +++-- + 2 files changed, 8 insertions(+), 4 deletions(-) + +diff -u -a -r1.40 -r1.40.10.1 +--- a/trans/Makefile 6 Jun 2007 16:08:56 -0000 1.40 ++++ b/trans/Makefile 7 Jun 2009 03:51:49 -0000 1.40.10.1 +@@ -26,13 +26,16 @@ + fakeroot.c proxy-defpager.c + OBJS = $(SRCS:.c=.o) fsysServer.o ifsockServer.o passwordServer.o \ + crashServer.o crash_replyUser.o msgServer.o \ +- default_pagerServer.o default_pagerUser.o \ ++ ourdefault_pagerServer.o ourdefault_pagerUser.o \ + device_replyServer.o elfcore.o + HURDLIBS = threads ports netfs trivfs iohelp fshelp pipe ihash shouldbeinlibc + password-LDLIBS = $(LIBCRYPT) + + include ../Makeconf + ++ourdefault_pager.defs: default_pager.defs ++ $(CPP) $(CPPFLAGS) -x c $< | sed -e '/MACH_MSG_TYPE_MAKE_SEND;/s/MAKE/COPY/' | sed -e '/subsystem/iserverprefix S_;' > $@ ++ + vpath elfcore.c $(top_srcdir)/exec + + symlink: fsysServer.o +@@ -40,7 +43,7 @@ + crash: crashServer.o crash_replyUser.o msgServer.o elfcore.o + password: passwordServer.o + streamio: device_replyServer.o +-proxy-defpager: default_pagerServer.o default_pagerUser.o ++proxy-defpager: ourdefault_pagerServer.o ourdefault_pagerUser.o + + proxy-defpager crash password streamio: ../libthreads/libthreads.a ../libports/libports.a ../libtrivfs/libtrivfs.a ../libthreads/libthreads.a ../libfshelp/libfshelp.a + fifo new-fifo: ../libpipe/libpipe.a +diff -u -a -r1.5 -r1.5.10.1 +--- a/trans/proxy-defpager.c 6 Jun 2007 16:08:56 -0000 1.5 ++++ b/trans/proxy-defpager.c 7 Jun 2009 03:51:49 -0000 1.5.10.1 +@@ -23,9 +23,10 @@ + #include <error.h> + #include <version.h> + #include <hurd/paths.h> ++#include <string.h> + +-#include "default_pager_S.h" +-#include "default_pager_U.h" ++#include "ourdefault_pager_S.h" ++#include "ourdefault_pager_U.h" + + static mach_port_t real_defpager, dev_master; + diff --git a/debian/patches/rc.patch b/debian/patches/rc.patch new file mode 100644 index 00000000..228bb349 --- /dev/null +++ b/debian/patches/rc.patch @@ -0,0 +1,78 @@ +More debianish rc scripts +--- + daemons/rc.sh | 43 ++++++++++++++++++++++++++++++++----------- + 1 file changed, 32 insertions(+), 11 deletions(-) + +--- a/daemons/rc.sh ++++ b/daemons/rc.sh +@@ -19,14 +19,17 @@ then + echo Automatic boot in progress... + date + +- /sbin/fsck --preen --writable ++ fsysopts / --update --readonly ++ /sbin/fsck -p -A + + case $? in + # Successful completion + 0) ++ fsysopts / --update --writable + ;; + # Filesystem modified (but ok now) + 1 | 2) ++ fsysopts / --update --writable + ;; + # Fsck couldn't fix it. + 4 | 8) +@@ -85,7 +88,15 @@ if test -d /tmp; then + + fi + if test -d /var/run; then +- (cd /var/run && { rm -rf -- *; cp /dev/null utmp; chmod 644 utmp; }) ++ (cd /var/run && { ++ find . ! -type d ! -name utmp ! -name innd.pid \ ++ -exec rm -f -- {} \; ++ cp /dev/null utmp ++ if grep -q ^utmp: /etc/group ++ then ++ chmod 664 utmp ++ chgrp utmp utmp ++ fi; }) + fi + echo done + +@@ -104,15 +115,25 @@ touch /var/run/mtab + + chmod 664 /etc/motd + +-echo -n starting daemons: ++( ++ trap ":" INT QUIT TSTP + +-/sbin/syslogd && echo -n ' syslogd' +-/sbin/inetd && echo -n ' inetd' +- +-if test -x /sbin/sendmail -a -r /etc/sendmail.cf; then +- /sbin/sendmail -bd -q30m && echo -n ' sendmail' +-fi +- +-echo . ++ if [ -d /etc/rc.boot ] ++ then ++ for i in /etc/rc.boot/S* ++ do ++ [ ! -f $i ] && continue ++ $i start ++ done ++ fi ++ if [ -d /etc/rc2.d ] ++ then ++ for i in /etc/rc2.d/S* ++ do ++ [ ! -f $i ] && continue ++ $i start ++ done ++ fi ++) + + date diff --git a/debian/patches/runsystem_setup_pflocal.patch b/debian/patches/runsystem_setup_pflocal.patch new file mode 100644 index 00000000..cd5a79eb --- /dev/null +++ b/debian/patches/runsystem_setup_pflocal.patch @@ -0,0 +1,21 @@ +Automatically setup local sockets if not already done so. Needed early for shell +pipelines. +--- + daemons/runsystem.sh | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/daemons/runsystem.sh ++++ b/daemons/runsystem.sh +@@ -53,6 +53,12 @@ function singleuser () + } + + ++# See whether pflocal is setup already, and do so if not (install case) ++ ++if ! test -e /servers/socket/1 && which settrans >/dev/null ; then ++ settrans -c /servers/socket/1 /hurd/pflocal ++fi ++ + # We expect to be started by console-run, which gives us no arguments and + # puts FALLBACK_CONSOLE=file-name in the environment if our console is + # other than a normal /dev/console. diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 00000000..cbb8a6bf --- /dev/null +++ b/debian/patches/series @@ -0,0 +1,33 @@ +console_utf-8.patch +diskfs_no_inherit_dir_group.patch +ext2fs_large_stores.patch +hurd_console_startup.patch +init_try_runsystem.gnu.patch +install-msgids.diff +libpager_update_seqno.patch +libpthread_stubs.patch +libpthread_tls.patch +makedev.diff +pfinet_dhcp.patch +pflocal.patch +rc.patch +runsystem_setup_pflocal.patch +startup-usr-support.patch +tmp_exec_startup.patch +uptime_w_path_fix.patch +stat_round.patch +libports_stability.patch +libpthread_fix.patch +extern_inline_fix.patch +proxy-defpager.diff +libpthread_procfs.patch +makedev_keep_options.patch +makedev_parted_store.patch +console_ignore_bdf_err.patch +libpthread_sigmask.patch +ext2fs_nowait.patch +libpager_deadlock.patch +libdiskfs_self-reauth.patch +libdiskfs_sync.patch +libpthread_globsigdisp.patch +posix-sigcodes.patch diff --git a/debian/patches/startup-usr-support.patch b/debian/patches/startup-usr-support.patch new file mode 100644 index 00000000..1d705fc9 --- /dev/null +++ b/debian/patches/startup-usr-support.patch @@ -0,0 +1,27 @@ +Debian GNU/Hurd has a real /usr +--- + daemons/rc.sh | 2 +- + daemons/runsystem.sh | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +--- a/daemons/rc.sh ++++ b/daemons/rc.sh +@@ -1,6 +1,6 @@ + #!/bin/bash + +-PATH=/bin:/sbin ++PATH=/bin:/sbin:/usr/bin:/usr/sbin + + # Start the default pager. It will bail if there is already one running. + /hurd/mach-defpager +--- a/daemons/runsystem.sh ++++ b/daemons/runsystem.sh +@@ -11,7 +11,7 @@ + ### Where to find programs, etc. + ### + +-PATH=/bin:/sbin ++PATH=/bin:/sbin:/usr/bin:/usr/sbin + export PATH + + umask 022 diff --git a/debian/patches/stat_round.patch b/debian/patches/stat_round.patch new file mode 100644 index 00000000..38454ba6 --- /dev/null +++ b/debian/patches/stat_round.patch @@ -0,0 +1,52 @@ +--- + libdiskfs/file-utimes.c | 4 ++-- + libdiskfs/node-times.c | 6 +++--- + 2 files changed, 5 insertions(+), 5 deletions(-) + +--- a/libdiskfs/file-utimes.c ++++ b/libdiskfs/file-utimes.c +@@ -33,7 +33,7 @@ diskfs_S_file_utimes (struct protid *cre + else + { + np->dn_stat.st_atim.tv_sec = atime.seconds; +- np->dn_stat.st_atim.tv_nsec = atime.microseconds * 1000; ++ np->dn_stat.st_atim.tv_nsec = 0; + np->dn_set_atime = 0; + } + +@@ -42,7 +42,7 @@ diskfs_S_file_utimes (struct protid *cre + else + { + np->dn_stat.st_mtim.tv_sec = mtime.seconds; +- np->dn_stat.st_mtim.tv_nsec = mtime.microseconds * 1000; ++ np->dn_stat.st_mtim.tv_nsec = 0; + np->dn_set_mtime = 0; + } + +--- a/libdiskfs/node-times.c ++++ b/libdiskfs/node-times.c +@@ -53,21 +53,21 @@ diskfs_set_node_times (struct node *np) + if (np->dn_set_mtime) + { + np->dn_stat.st_mtim.tv_sec = t.tv_sec; +- np->dn_stat.st_mtim.tv_nsec = t.tv_usec * 1000; ++ np->dn_stat.st_mtim.tv_nsec = 0; + np->dn_stat_dirty = 1; + np->dn_set_mtime = 0; + } + if (np->dn_set_atime) + { + np->dn_stat.st_atim.tv_sec = t.tv_sec; +- np->dn_stat.st_atim.tv_nsec = t.tv_usec * 1000; ++ np->dn_stat.st_atim.tv_nsec = 0; + np->dn_stat_dirty = 1; + np->dn_set_atime = 0; + } + if (np->dn_set_ctime) + { + np->dn_stat.st_ctim.tv_sec = t.tv_sec; +- np->dn_stat.st_ctim.tv_nsec = t.tv_usec * 1000; ++ np->dn_stat.st_ctim.tv_nsec = 0; + np->dn_stat_dirty = 1; + np->dn_set_ctime = 0; + } diff --git a/debian/patches/tmp_exec_startup.patch b/debian/patches/tmp_exec_startup.patch new file mode 100644 index 00000000..bd605718 --- /dev/null +++ b/debian/patches/tmp_exec_startup.patch @@ -0,0 +1,54 @@ +Also try /tmp/exec as it's used for installation. + +TODO: not used by d-i. Is it used by crosshurd? +--- + libdiskfs/boot-start.c | 24 ++++++++++++++++++++---- + 1 file changed, 20 insertions(+), 4 deletions(-) + +--- a/libdiskfs/boot-start.c ++++ b/libdiskfs/boot-start.c +@@ -126,8 +126,13 @@ diskfs_start_bootstrap () + assert (_hurd_ports); + assert (_hurd_ports[INIT_PORT_CRDIR].port != MACH_PORT_NULL); + diskfs_exec = file_name_lookup (_SERVERS_EXEC, 0, 0); +- if (diskfs_exec == MACH_PORT_NULL) +- error (1, errno, "%s", _SERVERS_EXEC); ++ if (diskfs_exec == MACH_PORT_NULL) ++ { ++ /* Debian specifc work-around for install bootstrapping. */ ++ diskfs_exec = file_name_lookup ("/tmp/exec", 0, 0); ++ if (diskfs_exec == MACH_PORT_NULL) ++ error (1, errno, "%s", _SERVERS_EXEC); ++ } + else + { + #ifndef NDEBUG +@@ -177,8 +182,15 @@ diskfs_start_bootstrap () + &retry, pathbuf, &execnode); + if (err) + { +- error (0, err, "cannot set translator on %s", _SERVERS_EXEC); +- mach_port_deallocate (mach_task_self (), diskfs_exec_ctl); ++ /* If /servers/exec is not available (which is the case during ++ installation, try /tmp/exec as well. */ ++ err = dir_lookup (root_pt, "/tmp/exec", O_NOTRANS, 0, ++ &retry, pathbuf, &execnode); ++ if (err) ++ { ++ error (0, err, "cannot set translator on %s", _SERVERS_EXEC); ++ mach_port_deallocate (mach_task_self (), diskfs_exec_ctl); ++ } + } + else + { +@@ -393,6 +405,10 @@ diskfs_execboot_fsys_startup (mach_port_ + + err = dir_lookup (rootport, _SERVERS_EXEC, flags|O_NOTRANS, 0, + &retry, pathbuf, real); ++ if (err) ++ /* Try /tmp/exec as well, in case we're installing. */ ++ err = dir_lookup (rootport, "/tmp/exec", flags|O_NOTRANS|O_CREAT, 0, ++ &retry, pathbuf, real); + assert_perror (err); + assert (retry == FS_RETRY_NORMAL); + assert (pathbuf[0] == '\0'); diff --git a/debian/patches/uptime_w_path_fix.patch b/debian/patches/uptime_w_path_fix.patch new file mode 100644 index 00000000..a2e595ef --- /dev/null +++ b/debian/patches/uptime_w_path_fix.patch @@ -0,0 +1,16 @@ +Debian has a real /usr and uses w-hurd file name +--- + utils/uptime.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/utils/uptime.sh ++++ b/utils/uptime.sh +@@ -25,7 +25,7 @@ + USAGE="Usage: $0 [OPTION...]" + DOC="Show system uptime, number of users, and load" + +-W=${W-/bin/w} ++W=${W-/usr/bin/w-hurd} + + while :; do + case "$1" in |