*/
#include <stddef.h>
+#include <gpxe/async.h>
#include <gpxe/aoe.h>
/** @file
struct aoe_device *aoedev
= container_of ( ata, struct aoe_device, ata );
struct async async;
- int rc;
- async_init_orphan ( &async );
- if ( ( rc = aoe_issue ( &aoedev->aoe, command, &async ) ) != 0 )
- return rc;
- async_wait ( &async, &rc, 1 );
- return rc;
+ return async_block ( &async, aoe_issue ( &aoedev->aoe, command,
+ &async ) );
}
/**
*/
#include <stddef.h>
+#include <gpxe/async.h>
#include <gpxe/iscsi.h>
/** @file
struct iscsi_device *iscsidev
= container_of ( scsi, struct iscsi_device, scsi );
struct async async;
- int rc;
- async_init_orphan ( &async );
- if ( ( rc = iscsi_issue ( &iscsidev->iscsi, command, &async ) ) != 0 )
- return rc;
- async_wait ( &async, &rc, 1 );
- return rc;
+ return async_block ( &async, iscsi_issue ( &iscsidev->iscsi, command,
+ &async ) );
}
/**
iscsidev->scsi.command = iscsi_command;
iscsidev->scsi.lun = iscsidev->iscsi.lun;
- rc = init_scsidev ( &iscsidev->scsi );
- if ( rc != 0 ) {
- fini_iscsidev ( iscsidev );
- }
+ if ( ( rc = init_scsidev ( &iscsidev->scsi ) ) != 0 )
+ goto err;
+
+ return 0;
+
+ err:
+ fini_iscsidev ( iscsidev );
return rc;
}
return async_init ( async, &orphan_async_operations, NULL );
}
+/**
+ * Execute and block on an asynchronous operation
+ *
+ * @v async_temp Temporary asynchronous operation structure to use
+ * @v START Code used to start the asynchronous operation
+ * @ret rc Return status code
+ *
+ * This is a notational shorthand for writing
+ *
+ * async_init_orphan ( &async_temp );
+ * if ( ( rc = START ) == 0 )
+ * async_wait ( &async_temp );
+ * if ( rc != 0 ) {
+ * ...handle failure...
+ * }
+ *
+ * and allows you instead to write
+ *
+ * if ( ( rc = async_block ( &async_temp, START ) ) != 0 ) {
+ * ...handle failure...
+ * }
+ *
+ * The argument START is a code snippet; it should initiate an
+ * asynchronous operation as a child of @c async_temp and return an
+ * error status code if it failed to do so (e.g. due to malloc()
+ * failure).
+ */
+#define async_block( async_temp, START ) ( { \
+ int rc; \
+ \
+ async_init_orphan ( async_temp ); \
+ if ( ( rc = START ) == 0 ) \
+ async_wait ( async_temp, &rc, 1 ); \
+ rc; \
+ } )
+
#endif /* _GPXE_ASYNC_H */
#include <byteswap.h>
#include <vsprintf.h>
#include <gpxe/in.h>
+#include <gpxe/ip.h>
#include <gpxe/dhcp.h>
#include <gpxe/async.h>
#include <gpxe/netdevice.h>
printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
memset ( &dhcp, 0, sizeof ( dhcp ) );
dhcp.netdev = netdev;
- async_init_orphan ( &async );
- if ( ( rc = start_dhcp ( &dhcp, &async ) ) != 0 ) {
- printf ( "could not start (%s)\n", strerror ( rc ) );
- return rc;
- }
- async_wait ( &async, &rc, 1 );
- if ( rc != 0 ) {
+ if ( ( rc = async_block ( &async,
+ start_dhcp ( &dhcp, &async ) ) ) != 0 ) {
printf ( "failed (%s)\n", strerror ( rc ) );
return rc;
}
}
}
- async_init_orphan ( &async );
- if ( ( rc = download ( uri, &buffer, &async ) ) != 0 )
- goto err;
- async_wait ( &async, &rc, 1 );
- if ( rc != 0 )
+ if ( ( rc = async_block ( &async,
+ download ( uri, &buffer, &async ) ) ) != 0 )
goto err;
/* Fill in buffer address and length */